diff --git a/data-structures/Circular_Linked_List.cpp b/data-structures/Circular_Linked_List.cpp new file mode 100644 index 00000000..0e363d18 --- /dev/null +++ b/data-structures/Circular_Linked_List.cpp @@ -0,0 +1,57 @@ +#include +#include + +using namespace std; + +int main() +{ + +struct node{ + int info; + node *next; +}*ptr,*head,*start; + +int c=1,data; + +ptr=new node; +ptr->next=NULL; + +start=head=ptr; + +while(c<3 && c>0){ + cout<<"1.Insert\n2.Link List\n"; + cin>>c; + + switch(c){ + case 1: + cout<<"Enter Data\n"; + cin>>data; + + ptr=new node; + ptr->next=start; + ptr->info=data; + + head->next=ptr; + head=ptr; + + break; + + case 2: + ptr=start->next; + + while(ptr!=start && ptr!=NULL){ + cout<info<<"->"; + ptr=ptr->next; + } + cout<<"\n"; + break; + + default: + cout<<"Wrong Choice\nExiting...\n"; + } + +} + +getch(); +return 0; +} \ No newline at end of file diff --git a/data-structures/Doubly_Linked_List.cpp b/data-structures/Doubly_Linked_List.cpp new file mode 100644 index 00000000..782c1b2c --- /dev/null +++ b/data-structures/Doubly_Linked_List.cpp @@ -0,0 +1,93 @@ +#include +#include + +using namespace std; +int main() +{ +struct node{ + int info; + node *left,*right; +}*ptr,*start,*last,*save; + +int c=1,i=0,data,item; +start=last=NULL; + +while(c<4 && c>0){ + cout<<"1.Insert\n2.Deletion\n3.Link List\n"; + cin>>c; + + switch(c){ + case 1: + cout<<"Enter Data\n"; + cin>>data; + + ptr=new node; + ptr->info=data; + ptr->left=last; + ptr->right=NULL; + + if(start==NULL){ + start=last=ptr; + } + + else{ + last->right=ptr; + last=ptr; + } + break; + + case 2: + if(start==NULL){ + cout<<"Underflow\n"; + } + + else{ + cout<<"Enter Item to be Deleted\n"; + cin>>item; + ptr=start; + + while(ptr!=NULL){ + if(ptr->info==item){ + i++; + if(ptr==start){ + start->left=NULL; + start=start->right; + } + + else{ + ptr->left->right=ptr->right; + ptr->right->left=ptr->left; + } + delete ptr; + cout<<"Item Deleted\n"; + } + ptr=ptr->right; + } + + if(i==0){ + cout<<"Item Does not exist\n"; + } + i=0; + } + break; + + case 3: + + ptr=start; + + while(ptr!=NULL){ + cout<info<<"->"; + ptr=ptr->right; + } + cout<<"\n"; + break; + + default: + cout<<"Wrong Choice\nExiting...\n"; + } + +} + +getch(); +return 0; +} \ No newline at end of file