Download presentation

Presentation is loading. Please wait.

Published byHunter Milliman Modified over 2 years ago

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
Free Store Allocation in c++ struct Node { char info; Node *next; }; Node *ptr; ptr = new Node; ptr->info; ptr->next; delete ptr;

6
Insertion Beginning MID END

7
Insertion in Link List #include 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); }

8
Insertion in Link List 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 info ”; np=np->next; } cout<<“!!!\n”; } void insert_end(Node *np) { if( start= =NULL) start=rear=np; else { rear->next=np; rear=np;} }

9
Deletion in Link List #include 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( ); }

10
Deletion in Link List 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 info ”; np=np->next; } cout<<“!!!\n”; } void delnode( ) { if( start= =NULL) cout<<“Underflow”; else { ptr=start; start=start->next; delete ptr;} }

11
Traversal in Link List #include 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); }

12
Traversal in Link List 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 info ”; np=np->next; } cout<<“!!!\n”; } void traverse(Node *np) { while(np!= NULL) { cout info ”; np=np->next; } cout<<“!!!\n”; }

13
Stack 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.

14
Stack Operation

15
Queues 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.

16
Queues

17
Application of Stack :Polish Strings PUSHA B ADD PUSHC D ADD MUL POPX

Similar presentations

OK

Programming Practice 3 - Dynamic Data Structure - 2006. 05. 08.

Programming Practice 3 - Dynamic Data Structure - 2006. 05. 08.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on hindu religion beliefs Ppt on first conditional game Ppt on endangered species of flora and fauna in india Ppt on preservation of public property search Ppt on credit policy and procedure Ppt on standing order activation Ppt on artificial intelligence free download Ppt on prepositions for grade 5 Download ppt on smart note taker Ppt on bodybuilding workouts