Skip to main content

Posts

Showing posts from 2018

Single Circular Linked List

/* circuler link list  */ //Single Circular Linked List #include<iostream> using namespace std; class cnode { private: int data; cnode *next; public: void insert(); void add(); void search(); void update(); void delet(); void show(); }; cnode *head=NULL; cnode *tail=NULL; cnode *current=NULL; cnode *temp=NULL; int p,num; int size=0; int main() { cnode c1; string x; while(1) { cout<<"\n\n1 to insert node"<<endl; cout<<"\n2 to Add node"<<endl; cout<<"\n3 to Search in Nodes"<<endl; cout<<"\n4 to update a value"<<endl; cout<<"\n5 to delete a node"<<endl; cout<<"\n6 to display"<<endl; cout<<"\n7 to exit: "; cin>>x; if(x=="1") { c1.insert(); } else if(x=="2") { c1.add(); } else if(x=="3") { c1.search(); } else if(x=="4") { c1.update(); } else...

double link list

/* double link list */ #include<iostream> using namespace std; class dnode { private: dnode *prev; int data; dnode *next; public: void insert(); void add(); void search(); void update(); void delet(); void show(); }; dnode *head=NULL; dnode *tail=NULL; dnode *temp=NULL; dnode *current=NULL; int size=0; int num,p; int main() { dnode d1; string x; while(1) { cout<<"\n -------------------------------"<<endl; cout<<"\n\n=> 1 to insert node"<<endl; cout<<"\n=> 2 to Add node"<<endl; cout<<"\n=> 3 to Search in Nodes"<<endl; cout<<"\n=> 4 to update a value"<<endl; cout<<"\n=> 5 to delete a node"<<endl; cout<<"\n=> 6 to display"<<endl; cout<<"\n=> 7 to exit: "; cin>>x; cout<<"\n -------------...

stack using link list

/* stack using link list   */ #include<iostream> using namespace std; class node { private: int data; node *next; public: void push(); void pop(); void show(); }; node *head=NULL; node *tail=NULL; node *current=NULL; node *temp=NULL; int num; int size=0; int main() { node n; string x; while(1) { cout<<"\n\n1 to Push"<<endl; cout<<"\n2 to Pop"<<endl; cout<<"\n3 to Display"<<endl; cout<<"\n4 to exit: "; cin>>x; if(x=="1") { n.push(); } else if(x=="2") { n.pop(); } else if(x=="3") { n.show(); } else if(x=="4") { return 0; } else { cout<<"\nInvalid Command\n"<<endl; } } } //push Function void node::push() { cout<<"\nEnter value: "; cin>>num; temp=new node; temp->data=...

BST with deletion (binary search tree with deletion )

/* Binary tree with deleteion code any problem contact me ikkhan5757@gmail.com */ #include<iostream> #include<windows.h> #include<conio.h> using namespace std; class node; node* first=NULL; node* new_node=NULL; node* current=NULL; class node{ public: int data; node* left; node* right; int add(int num){ new_node=new node; new_node->data=num; new_node->left=NULL; new_node->right=NULL; if(first==NULL){ first=new_node; return 0; } current=first; while(1){ if( (current->data) > (new_node->data) ){ //  when child is less than parrent if( current->left == NULL){        //  if left is empty child of parent current->left=new_node; return 0; } current=current->left; } else{     if(current->right==NULL){ current->right=new_node; return 0; } current=current->right; } ...