c++ - Define String Node in Linked List -
#include<iostream> #include<stdlib.h> #include<conio.h> #include <ctime> #include <fstream> #include <windows.h> #include <string> using namespace std; /* data variable used store data name suggests,the "next" pointer of type node used point next node of linked list*/ /* * node declaration */ struct node { string info; struct node *next; }*start; /* * class declaration */ class single_llist { public: node* create_node(string); void insert_begin(); void insert_pos(); void insert_last(); void delete_pos(); void sort(); void search(); void update(); void reverse(); void display(); single_llist() { start = null; } }; /* * inserting element in beginning */ void single_llist::insert_begin() { string value; cout<<"enter value inserted: "; cin>>value; struct node *temp, *p; temp = create_node(value); if (start == null) { start = temp; start->next = null; } else { p = start; start = temp; start->next = p; } cout<<"element inserted @ beginning"<<endl; }
i'm developing program dev c ++ program.i trying entering specific words txt file , save them.therefore i'm dealing string.the program gives error: undefined reference single_llist::create_node(std::string)
, showing me there mistake here, temp = create_node(value);
i still researching need solving problem?
thanks @nathanoliver think tried wrong way without creating node first.for creating node check following code fragment.
/* * creating node */ node *single_llist::create_node(string value) { struct node *temp, *s; temp = new(struct node); if (temp == null) { cout<<"memory not allocated "<<endl; return 0; } else { temp->info = value; temp->next = null; return temp; } }
Comments
Post a Comment