WELCOME TO Linked List, Stack & Queue By VINAY ALEXANDER PGT COMPUTER SCIENCE) KV JHAGRAKHAND.

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

Linked Lists Linked Lists Representation Traversing a Linked List
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
LINKED LIST, STACKS AND QUEUES Saras M Srivastava, PGT – Comp. Sc. Kendriya Vidyalaya TengaValley.
CHP-5 LinkedList.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
WELCOME TO Linked List, Stack & Queue By VINAY ALEXANDER PGT COMPUTER SCIENCE) KV JHAGRAKHAND.
WELCOME TO Linked List, Stack & Queue By Sumit Kumar PGT(CS) KV, Samba.
Stack and Queue Dr. Bernard Chen Ph.D. University of Central Arkansas.
Linked Lists in C and C++ By Ravi Prakash PGT(CS).
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Stack  A stack is a linear data structure or abstract data type for collection of items, with the restriction that items can be added one at a time and.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
UNIT-2. Singly Linked List Doubly Linked List Circular Linked List Representing Stack with Linked List. Representing Queue with Linked List.
Reference: Vinu V Das, Principles of Data Structures using C and C++
Implementation of Linked List For more notes and topics visit: eITnotes.com.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
D ATA S TRUCTURE Ali Abdul Karem Habib MSc.IT. P OINTER A pointer is a variable which represents the location of a data item. We can have a pointer to.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 17: Linked Lists.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
List Interface and Linked List Mrs. Furman March 25, 2010.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
LINEAR LINKED LISTS The disadvantages of arrays: 1.The size of the array is fixed. 2.Large size of array??? 3. Inserting and deleting elements. If the.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15 1.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Linked List. LINKED LIST Link is collection of similar type of elements. There are two ways of maintaining a list in memory. The first way is store the.
Data Structure & Algorithms
Computer Science Department Data Structure and Algorithms Lecture 3 Stacks.
1 Linked List. 2 List A list refers to a sequence of data items  Example: An array The array index is used for accessing and manipulation of array elements.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
UNIT-II Topics to be covered Singly linked list Circular linked list
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part R2. Elementary Data Structures.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
STACKS & QUEUES for CLASS XII ( C++).
What is a Queue? Queue is a linear data structure in which the insertion and deletion operations are performed at two different ends. In a queue data structure,
Data Structures Using C, 2e
Queues.
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
5.13 Recursion Recursive functions Functions that call themselves
Lectures linked lists Chapter 6 of textbook
Program based on queue & their operations for an application
Linked Lists Chapter 6 Section 6.4 – 6.6
Data Structure Interview Question and Answers
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
DATA STRUCTURE QUEUE.
Arrays and Linked Lists
Linked Lists.
LINKED LIST.
Review & Lab assignments
KENDRIYA VIDYALAYA SANGATHAN (AGRA REGION)
BY PROF. IRSHAD AHMAD LONE.
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
Presentation transcript:

WELCOME TO Linked List, Stack & Queue By VINAY ALEXANDER PGT COMPUTER SCIENCE) KV JHAGRAKHAND

Linked-List A link-list is a linear collection of data elements, called nodes pointing to the next nodes by means of pointers. A linked list consists of a series of nodes which are not necessarily adjacent in memory. Link Data Elements

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.

Memory Allocation (Dynamics Vs Static) Each data element, stored in the memory,is given some memory. this process of giving memory is called memory allocation. Static memory: This memory allocation technique reserves fixed amount of memory before actual processing takes place, therefore the number of elements to be stored must be predetermined. Example: Array Dynamic Memory Allocation: An allocation of memory during the program execution itself, as and when required.Example: Link List

Array vs. Linked List An array is a static data structure. It cannot be created nor destroyed during program execution. So there is a lot of memory wastage. Size of an array should be known in advance. In array, insertion and deletion require lot of shifting. All these problems are eliminated in linked list

(45)(32) (34)(39)(20) (11) (6)(25) (9) Example of a Linked List

A 000B 000C 000D 000E 000F A 001B 001C 001D 001E 001F Memory Linked list inside the Computer Memory

A 000B 000C 000D 000E 000F Memory A 001B 001C 001D 001E 001F 0002 Linked list inside the Computer Memory

A 000B 000C 000D 000E 000F Memory A 001B 001C 001D 001E 001F Linked list inside the Computer Memory

A 000B 000C 000D 000E 000F Memory A 001B 001C 001D 001E 001F Linked list inside the Computer Memory

Singly, Doubly and Circular Linked List

Free Store Allocation in c++ In C++,Every program is provided with a pool of unallocated memory that it may utilize during execution. this memory is known as free store memory. Free store memory is allocated by applying operator new to a type specifier and which returns a pointer to the allocated memory.

Free Store Allocation in c++ struct Node {char info; Node *next; }; Node *ptr; ptr = new Node; To Refered to info part,we may write ptr->info; To Refered to next pointer,we may write ptr->next; When a node is deleted, it is done as delete ptr;

Basic Operations on singly linked list: New ITEM is either added in beginning of the list or in the middle of the list or in the end of the list. T o add an ITEM in the beginning of the list, START is modified to point to the new node of ITEM and the nest pointer of the new node(i.e, ITEM node) points to the previous first node. T o add an ITEM in the end of the list, nest pointer of the last node is made to point to the new ITEM’s node and the next pointer of the new ITEM/s node is made NULL. IF you try to insert a node,when there is no memory available,it is called “OVERFLOW”

Insertion Beginning MID END

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); }

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;} }

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( ); }

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;} }

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); }

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”; }

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.

Stack Operation

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.

Queues

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