Posts

Showing posts from May, 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(); }

Telephone Directory Using BST

Source Code: #include <iostream> #include <string> using namespace std; struct phone{  int Num;  int code; string address; string name; phone*right; phone*left; };phone*root=NULL; phone*nodeptr=NULL; //insert void insert(string nme,string add, int phno,int Code) { phone*p=new phone; p->name=nme; p->address=add; p->Num=phno; p->code=Code; p->right=NULL; p->left=NULL; if(root==NULL) { root=p; cout<<"PHone nUmber is saved \n"; } else {       nodeptr=root; while(nodeptr!=NULL) { if(phno<nodeptr->Num) { if(nodeptr->left!=NULL) { nodeptr=nodeptr->left; } else { nodeptr->left=p; cout<<"PHone nUmber is saved \n"; break; } } else if(phno>nodeptr->Num) { if(nodeptr->right!=NULL) { nodeptr=nodeptr->ri...

Data Structure LAb 10

Source Code: #include <iostream> using namespace std; struct tree { int num; tree*left=NULL; tree*right=NULL; };tree*root=NULL; tree*nodeptr=NULL; //add tree void add(int n) { tree* t=new tree; t->num=n; t->left=NULL; t->right=NULL; bool flag=false; if(root==NULL) { root=t; flag=true; } else { nodeptr=root; while(nodeptr!=NULL) { if(n<nodeptr->num) { if(nodeptr->left!=NULL) { nodeptr=nodeptr->left; } else { nodeptr->left=t; flag=true; break; } } else if(n>nodeptr->num) { if(nodeptr->right!=NULL) { nodeptr=nodeptr->right; } else { flag=true; nodeptr->right=t; break; } } else { cout<<"Duplicate NUmber \n"; break; } } } if(flag==true) cout<<"Va...