1 / 18

WELCOME TO Linked List, Stack & Queue

WELCOME TO Linked List, Stack & Queue. By Sumit Kumar PGT(CS) KV , Samba. Linked-List. A link-list is a linear collection of data elements, called nodes pointing to the next nodes by means of pointers.

goro
Download Presentation

WELCOME TO Linked List, Stack & Queue

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WELCOME TO Linked List, Stack & Queue By Sumit Kumar PGT(CS) KV , Samba

  2. Linked-List A link-list is a linear collection of data elements, called nodes pointing to the next nodes by means of pointers. A stack is a linear structure implemented in LIFO manner where insertions and deletions are restricted to occur only at one end – stack’s top. The stack is also a dynamic data structure as it can grow or shrink. A Queue is also a linear dynamic structure implemented in FIFO manner where insertions can occur at the “rear” end, and deletions occur only at “front” end.

  3. Important Point about Link list Linked list overcome the drawbacks of arrays as in linked list number of elements need not be predetermined, more memory can be allocated or released during the processing as and when required. Making insertions and deletions much easier and simpler.

  4. Singly, Doubly and Circular Linked List

  5. struct Node { char info; Node *next; }; Node *ptr; ptr = new Node; ptr->info; ptr->next; delete ptr; Free Store Allocation in c++

  6. Beginning Insertion MID END

  7. #include<iostream.h> #include<process.h> struct Node { int info; Node *next; } *start, *newptr, *save, *ptr, *rear; Node * create_new_node(int); void insert_beg(Node *); void insert_end(Node *); void display(Node *); void main( ) {start = NULL; int inf; cout<<“Enter info for new node”; cin>>inf; cout<<“create new node !!”; newptr= create_new_node(inf); if(newptr!=NULL) cout<<“Success”; else { cout<<“Cannot create”; exit(1);} cout<<“insert new node in the beginning of list”; insert_beg(newptr); //Or insert_end(newptr); display(start); } Insertion in Link List

  8. Node * create_new_node( int n) { ptr = new ptr; ptr->info=n; ptr->next=NULL; return ptr; } void insert_beg(Node *np) { if( start= =NULL) start=np; else { save=start; start=np; np->next=save;} } void display( Node *np) { while(np!=NULL) { cout<<np->info<<“->”; np=np->next; } cout<<“!!!\n”; } Insertion in Link List void insert_end(Node *np) { if( start= =NULL) start=rear=np; else { rear->next=np; rear=np;} }

  9. #include<iostream.h> #include<process.h> struct Node { int info; Node *next; } *start, *newptr, *save, *ptr, *rear; Node * create_new_node(int); void insert(Node *); void display(Node *); void delnode(Node *); void main( ) {start = rear = NULL; int inf; cout<<“Enter info for new node”; cin>>inf; cout<<“create new node !!”; newptr= create_new_node(inf); if(newptr!=NULL) cout<<“Success”; else { cout<<“Cannot create”; exit(1);} cout<<“insert new node in the beginning of list”; insert(newptr); display(start); delnode( ); } Deletion in Link List

  10. Node * create_new_node( int n) { ptr = new ptr; ptr->info=n; ptr->next=NULL; return ptr; } void insert(Node *np) { if( start= =NULL) start=rear=np; else { rear->next=np; rear=np;} } void display( Node *np) { while(np!=NULL) { cout<<np->info<<“->”; np=np->next; } cout<<“!!!\n”; } Deletion in Link List void delnode( ) { if( start= =NULL) cout<<“Underflow”; else { ptr=start; start=start->next; delete ptr;} }

  11. #include<iostream.h> #include<process.h> struct Node { int info; Node *next; } *start, *newptr, *save, *ptr, *rear; Node * create_new_node(int); void insert(Node *); void traverse(Node *); void main( ) {start = rear = NULL; int inf; cout<<“Enter info for new node”; cin>>inf; cout<<“create new node !!”; newptr= create_new_node(inf); if(newptr!=NULL) cout<<“Success”; else { cout<<“Cannot create”; exit(1);} insert(newptr); traverse(start); } Traversal in Link List

  12. Node * create_new_node( int n) { ptr = new ptr; ptr->info=n; ptr->next=NULL; return ptr; } void insert(Node *np) { if( start= =NULL) start=rear=np; else { rear->next=np; rear=np;} } void display( Node *np) { while(np!=NULL) { cout<<np->info<<“->”; np=np->next; } cout<<“!!!\n”; } Traversal in Link List void traverse(Node *np) { while(np!= NULL) { cout<<np->info <<“->”; np=np->next; } cout<<“!!!\n”; }

  13. Stack refer to the lists stored and accessed in a special way i.e. LIFO technique. In stack, insertion and deletions take place only at one end called the top. Stack

  14. Stack Operation

  15. Queues are FIFO lists, where insertions take place at the “rear” end of the queue and deletions take place at the “front” end of the queues. Queues

  16. Queues

  17. Application of Stack :Polish Strings

  18. Thank You !!!

More Related