Posts

Showing posts from May 7, 2018

Read data from text file and store in doubly linked list

struct node{ int num; node*next=NULL; node*prev=NULL; };node*head=NULL; node*temp=NULL; void start() { int num; bool flag=false; ifstream myfile("file.txt"); while(!myfile.eof()) { myfile>>num; node*c=new node;   c->num= if(head==NULL) { head=c; flag=true; } else { temp=head; { while(temp->next!=NULL) { temp=temp->next; } temp->next=c; c->prev=temp; } } } myfile.close(); }