diff --git a/C Programming Language/Linked Lists/Doubly Linked lists/doublyll.cpp b/C Programming Language/Linked Lists/Doubly Linked lists/doublyll.cpp new file mode 100644 index 0000000..5352562 --- /dev/null +++ b/C Programming Language/Linked Lists/Doubly Linked lists/doublyll.cpp @@ -0,0 +1,261 @@ +//Program for performing operations on doubly linked list + +#include +#include +using namespace std; + +class node +{ +friend class list; +int data; +node *prev; +node *next; + +public: +node(int d) +{ + prev=NULL; + data=d; + next=NULL; +} + +}; + +class list +{ + node *head; + +public: + list() + { + head=NULL; + } + void createmember() + { + int data; + char choice; + node *temp,*ptr; + + do + { + + cout<<"Enter data: "; + cin>>data; + + temp= new node(data); + + if(head==NULL) + { + head=temp; + } + else + { + ptr=head; + while(ptr->next!=NULL) + { + ptr=ptr->next; + } + temp->prev=ptr; + ptr->next=temp; + } + cout<<"Node is inserted!"<>choice; + }while(choice=='y'||choice=='Y'); + + } + + void display() + { + + node *ptr; + + if(head==NULL) + { + cout<<"List is empty!"<data<<"\t"; + ptr=ptr->next; + } + cout<data > ptr2->data) + { + if(head==NULL) + { + head=ptr1; + ptr=ptr1; + } + else + { + ptr1->prev=ptr; + ptr->next=ptr1; + ptr=ptr->next; + } + ptr1=ptr1->next; + } + else if(ptr1->data < ptr2->data) + { + if(head==NULL) + { + head=ptr2; + ptr=ptr2; + } + else + { + ptr2->prev=ptr; + ptr->next=ptr2; + ptr=ptr->next; + } + ptr2=ptr2->next; + } + + } + if(ptr1!=NULL) + { + ptr1->prev=ptr; + ptr->next=ptr1; + } + if(ptr2!=NULL) + { + ptr2->prev=ptr; + ptr->next=ptr2; + + } + + display(); + + } + + +}; + +int main() { + + list l1,l2,l3; + int ch; + + cout<<"\n...LIST1..."<>ch; + switch(ch) + { + case 1: + cout<<"\n...LIST1..."<