SlideShare une entreprise Scribd logo
1  sur  49
Let’s learn  TACKS &  UEUES for  CLASS XII( C++) SENIOR SECONDARY GROUP Presented By : NITI ARORA
STACKS  AND  QUEUES
Objective ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A mathematical and logical model of data is known as  Data Structure .   Primitive data structure :  The data structure, which is available in the compiler, is known as a  primitive data structure . Non-primitive data structure :  The data structure, which is not available in the compiler, is known as  non-primitive data structure .   DATA STRUCTURE: INTRODUCTION
  Linear Data Structure :  The data structure in which each element has access to maximum of one predecessor element and maximum of one successor element is known as  linear data structure .  Example:  Stack, Queue, etc . Non-linear Data Structure :  The data structure in which each element can access any number of predecessor elements and any number of successor elements is known as  Non-linear data structure . Example:  Tree, Graphs, etc .   DATA STRUCTURE: INTRODUCTION
Static Data Structure:  The data structure in which the number of elements is fixed, is known as  Static Data Structure . Example: Arrays Dynamic Data Structure:  The data structure in which the number of elements is not fixed, is known as  Dynamic Data Structure . Example: Linked List. TYPES OF DATA STRUCTURE
It is a  static data structure . It is a homogeneous collection of data. The elements in the array are stored on consecutive memory locations. Array is also known as a subscripted variable, e.g., A[i] is i th   element of the array A. ARRAY
STACK It is a non-primitive linear data structure in which  insertion  and  deletion  of elements takes place from  only one end , known as top.   It is a non-primitive linear data structure in which  insertion  and  deletion  of elements takes place from  two opposite ends  rear and front respectively.  QUEUE
STACKS Stacks is LIFO (Last In First Out) structure and physically can be implemented as an array or as a linked list. Stack, when implemented as an array is functionally same as any other array except that here, adding an element and deletion is done from the same direction just like a pile of books.
STACK Inserting an element in an array is known as  PUSH . Deleting an element from an array is known as  POP . Implementation of STACK in computers ,[object Object],[object Object],[object Object]
STACK A  stack  is a list in which insertion and deletion takes place only at one end called top. Thus, called LIFO. Representation  of STACK Each one of the above has one  open and one close  end and  data movement takes place from open end . data4 TOP data3 data2 data1 data2 data1 data3 data4 TOP TOP data4 data3 data2 data1 data1 data2 data3 data4 TOP
Basic operation and implementation of stacks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STACKS The fundamental operations that can be performed on stack are  PUSH and POP . When element is added on the stack top is called  PUSH .  And When Data is removed from the stack top, the operation is called  POP.
STACK The stack operation can be explained as follows:   Stack operation Content of array Push(a)   a Push(b)  ba Push( c)   cba Pop()   ba Pop()   a Push (a) a b a Push(b) b a C Push( c) b a Pop( c) a Pop(b)
STACKS ,[object Object],[object Object],[object Object],[object Object]
Linear Stack int S[5]; When  PUSH  is selected,  TOP  is  incremented, And data is added at that subscript location When  POP  is selected,  TOP  is  decremented, And data is removed from that subscript location Stack array int TOP; To hold address of location where data is inserted or deleted
Lets see working of  Linear Stack   Push 7 Push 20 Push 14 ,[object Object],[object Object],TOP TOP TOP Top is incremented  TOP++ 10 9 8 10 9 8 7 10 9 8 7 20
CONTINUED…. Pop 20 Pop 7 ,[object Object],TOP Top Top TOP is decremented TOP -- 10 9 8 7 20 10 9 8 7 10 9 8
Lets see this using a program Program Code for the Same is  Click here to execute program Click here to see program code
A variable which holds an address of a memory location of another variable  is known as a  Pointer Variable (or only pointer).   Example int amt, *p; amt Requires 2 bytes 0x8ffebab4 *P Requires 2 bytes Pointer P holds address of amt POINTER     900     0x8ffebab4
NEW  operator in C++ returns the address of a block of unallocated bytes (depending on data  type a pointer pointing to). DELETE  operator in C++ reverses the process of new operator, by releasing the memory location from a pointer. It de allocates memory assigned by NEW. DYNAMIC ALLOCATION
A pointer, which stores the address of struct type data, is known as Pointer to structure. struct abc { int X,Y;  }; struct *g=new abc;  Holds address of dynamic object of struct abc   G   0x8ff134ab G->X 0x8ff134ab G->X G->Y LINK LIST To allocate dynamic allocation  and  store address in point g    
struct STACK // structure for stack { int data; STACK *link;  }; struct *TOP;  LINK STACK To hold address of First node of the list TOP pointer to holds address of dynamic objects of link stack. As we push a node TOP element get shifted and new node becomes first node.  LIFO implementation every new node becomes first node.  When we pop Top node is deleted and next node becomes first node.
Lets see working of  Linked stack * TOP * Temp NULL 0x8ffab2e6   A  new memory  is allocated and address is stored in temp X  NULL data  link 0x8ffab2e6   Top = Temp Top will hold address of new location * TOP 0x8ffab2e6   Thus,  TOP  will have this address. Push operation Initially top is assigned NULL Temp holds address of new location
Cont….. *TOP * Temp 0x8ffab2e6 0x8ffab2e8 Another  new memory  is allocated to an object Y data  link 0x8ffab2e8 * TOP 0x8ffab2e8 X  NULL data  link 0x8ffab2e6 temp-> link = Top Top=temp 0x8ffab2e6 Now TOP is TOP will get shifted Y becomes first node  X becomes second node
Cont….. * TOP * Temp 0x8ffab2e8 0x8ffab2e8 An  object  is deleted from top Y data  link 0x8ffab2e8 Thus Top will be * TOP 0x8ffab2e6 X  NULL data  link Temp=TOP TOP=TOP->link 0x8ffab2e6 delete temp  (to release memory) 0x8ffab2e6 TOP will get shifted X becomes first node  Y will be released POP operation
Lets see this using a program Program Code for the Same is  Click here to execute program Click here to see program code
Queues ,[object Object],Queue , when implemented as an array is functionally same as any other array except that here, adding an element and deletion is done from the one direction and deletion from other just like any queue of peoples.
Queues ,[object Object],[object Object],[object Object],Implementation of queue in computers ,[object Object]
Queue A Queue is a data structure in which insertion is done at the end and deletion is done from the front of queue. It is FIFO . Representation  of Queue Each one of the above has two  open  end Front and Rear. Insertion is done from Rear and deletion form Front Rear Front Front Rear Front Rear Front Rear data4 data3 data2 data2 data3 data4 data4 data3 data2 data2 data3 data4
Basic operation and implementation of QUEUE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
QUEUE The fundamental operations that can be performed on Queue are  Insert and Delete . When element is added on the Queue Front is called  Insert .  And When Data is removed from the Queue Rear, the operation is called  Delete.
QUEUE The Queue operation can be explained as follows:   Queue operation Content of array Insert(a)   Front=0 Rear=0 Insert(b)  Front=0 Rear=1 Insert( c)   Front=0 Rear=2 Delete()   Front=1 Rear=2 Delete()   Front=2 Rear=2 If we try to insert Overflow occurs Though first two cells are empty a b a c b a c b c
Linear Queue int Q[5]; When  INSERT  is selected,  Rear  is  incremented, And data is added at that subscript location When  DELETE  is selected,  Front  is  decremented, And data is removed from that subscript location Queue array int Front, Rear; To hold address of location where data is inserted or deleted
QUEUE ,[object Object],[object Object],[object Object],[object Object]
Lets see working of  LINEAR QUEUE Insert 7 Insert 20 Insert 14 OVERFLOW QUEUE  is full Front  rear rear rear Front Front Rear is incremented Rear++ 10 9 8 10 9 8 7 10 9 8 7 20
Lets see working of Queue as an array Delete Delete Underflow occurs when QUEUE  is empty Rear Front Rear Rear Front Front Front is incremented Front++ 10 9 8 7 20 9 8 7 20 8 7 20
Lets see this using a program Program Code for the Same is  Click here to execute program Click here to see program code
struct QUEUE // structure for QUEU { int data; QUEUE *link;  }; struct *Front,*Rear;  LINKED QUEUE To hold address of First and Last node of the list Front and Rear  pointer to holds address of dynamic objects of link stack. As we insert a node Rear element get shifted and new node becomes next node.  FIFO implementation every new node added at end. When we Delete Front node is deleted and next node becomes first node.
Lets see working of  Linked Queue * Front  * Rear * Temp NULL  NULL 0x8ffab2e6   A  new memory  is allocated and address is stored in temp X  NULL data  link 0x8ffab2e6   Front=Rear  = Temp Front and Rear  will hold address of First location * Front  * Rear 0x8ffab2e6   0x8ffab2e6   Thus,  Front and Rear  will have this address . Insert operation Initially Front and Rear is assigned NULL Temp holds address of new location
Cont….. *Front  * Rear * Temp 0x8ffab2e6  0x8ffab2e6 0x8ffab2e8 Another  new memory  is allocated to an object X data  link 0x8ffab2e6 * Rear 0x8ffab2e8 Y  NULL data  link 0x8ffab2e8 temp-> link = Rear Rear=temp 0x8ffab2e8 Now Rear is Rear will get shifted Y becomes Last node
Cont….. * Front  * Rear * Temp 0x8ffab2e6 0x8ffab2e8 0x8ffab2e6 An  object  is deleted from Front X data  link 0x8ffab2e6 Thus Front will be * Front 0x8ffab2e8 Y  NULL data  link Temp=Front Front=Front->link 0x8ffab2e8 delete temp  (to release memory) 0x8ffab2e8 Front will get shifted Y becomes first node  X will be released Delete operation
Lets see this using a program Program Code for the Same is  Click here to execute program Click here to see program code
CIRCULAR QUEUE The fundamental operations that can be performed on Circular Queue are  Insert and Delete . When overflow occurs though the free cells are available, Rear reaches ends Circular Queue is implemented to avoid this drawback. In Circular Queue as soon as Rear reaches maximum it should reset to 0.
QUEUE The Queue operation can be explained as follows:   Queue operation Content of array Insert(a)   Front=0 Rear=0 Insert(b)  Front=0 Rear=1 Insert( c)   Front=0 Rear=2 Delete()   Front=1 Rear=2 Insert (d)   Front=2 Rear=0 Overflow occurs only when Array is FULL. Rear moves to 0 if array is empty a b a c b a c b c d
Lets see this using a program Program Code for the Same is  Click here to execute program Click here to see program code
Do you have any QUESTIONS ?
TEST YOUR KNOWLEDGE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
THANKS NITI ARORA FROM

Contenu connexe

Tendances (20)

stack presentation
stack presentationstack presentation
stack presentation
 
stack & queue
stack & queuestack & queue
stack & queue
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Queues
QueuesQueues
Queues
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Data structures
Data structuresData structures
Data structures
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Array data structure
Array data structureArray data structure
Array data structure
 
Stack
StackStack
Stack
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 

En vedette

C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Examshishamrizvi
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTUREArchie Jamwal
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queueSrajan Shukla
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Queue and stacks
Queue and stacksQueue and stacks
Queue and stacksgrahamwell
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structureeShikshak
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueFarhanum Aziera
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 
Linked stacks and queues
Linked stacks and queuesLinked stacks and queues
Linked stacks and queuesRamzi Alqrainy
 
Ds inserting elem in array
Ds inserting elem in arrayDs inserting elem in array
Ds inserting elem in arrayTanya Makkar
 
CBSE, Grade12, Computer Science, Random Numbers - Notes
CBSE, Grade12, Computer Science, Random Numbers - NotesCBSE, Grade12, Computer Science, Random Numbers - Notes
CBSE, Grade12, Computer Science, Random Numbers - NotesMalathi Senthil
 

En vedette (20)

C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stack & queues
Stack & queuesStack & queues
Stack & queues
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Queue and stacks
Queue and stacksQueue and stacks
Queue and stacks
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Linked stacks and queues
Linked stacks and queuesLinked stacks and queues
Linked stacks and queues
 
Ds inserting elem in array
Ds inserting elem in arrayDs inserting elem in array
Ds inserting elem in array
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
 
CBSE, Grade12, Computer Science, Random Numbers - Notes
CBSE, Grade12, Computer Science, Random Numbers - NotesCBSE, Grade12, Computer Science, Random Numbers - Notes
CBSE, Grade12, Computer Science, Random Numbers - Notes
 
Introduction to XHTML
Introduction to XHTMLIntroduction to XHTML
Introduction to XHTML
 

Similaire à Stacks & Queues By Ms. Niti Arora

Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Getachew Ganfur
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUEDev Chauhan
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptxselemonGamo
 
Data Structure
Data Structure Data Structure
Data Structure Ibrahim MH
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptxline24arts
 
Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturergomathi chlm
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queueRai University
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueRai University
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 

Similaire à Stacks & Queues By Ms. Niti Arora (20)

Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUE
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptx
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
STACK1.pptx
STACK1.pptxSTACK1.pptx
STACK1.pptx
 
04 stacks
04 stacks04 stacks
04 stacks
 
Data Structure
Data Structure Data Structure
Data Structure
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
 

Plus de kulachihansraj

What Is Internet made by Ms. Archika Bhatia
What Is Internet made by Ms. Archika BhatiaWhat Is Internet made by Ms. Archika Bhatia
What Is Internet made by Ms. Archika Bhatiakulachihansraj
 
What Is A Network made by Ms. Archika Bhatia
What Is A Network made by Ms. Archika BhatiaWhat Is A Network made by Ms. Archika Bhatia
What Is A Network made by Ms. Archika Bhatiakulachihansraj
 
Similarity By Ms. Rashmi Kathuria
Similarity By Ms. Rashmi KathuriaSimilarity By Ms. Rashmi Kathuria
Similarity By Ms. Rashmi Kathuriakulachihansraj
 
Unit cube Activity 2 by Ms. Rashmi Kathuria
Unit cube Activity 2 by Ms. Rashmi KathuriaUnit cube Activity 2 by Ms. Rashmi Kathuria
Unit cube Activity 2 by Ms. Rashmi Kathuriakulachihansraj
 
unit cube Activity4 by Ms. Rashmi Kathuria
unit cube Activity4 by Ms. Rashmi Kathuriaunit cube Activity4 by Ms. Rashmi Kathuria
unit cube Activity4 by Ms. Rashmi Kathuriakulachihansraj
 
Unit cube Activity 1 by Ms. Rashmi Kathuria
Unit cube Activity 1 by Ms. Rashmi KathuriaUnit cube Activity 1 by Ms. Rashmi Kathuria
Unit cube Activity 1 by Ms. Rashmi Kathuriakulachihansraj
 
Unit-cubes Activity3 By Ms. Rashmi Kathuria
Unit-cubes Activity3 By Ms. Rashmi KathuriaUnit-cubes Activity3 By Ms. Rashmi Kathuria
Unit-cubes Activity3 By Ms. Rashmi Kathuriakulachihansraj
 
Hybridization By Ms. Manjula Agarwal
Hybridization By Ms. Manjula AgarwalHybridization By Ms. Manjula Agarwal
Hybridization By Ms. Manjula Agarwalkulachihansraj
 
Project Final Yogita Anand Kohli
Project Final Yogita Anand KohliProject Final Yogita Anand Kohli
Project Final Yogita Anand Kohlikulachihansraj
 
Social religious reform movements in India By Ms. Seema Lal
Social religious reform movements in India By Ms. Seema LalSocial religious reform movements in India By Ms. Seema Lal
Social religious reform movements in India By Ms. Seema Lalkulachihansraj
 
The Electric Circuit And Kirchhoff’S Rules by Students
The Electric Circuit And Kirchhoff’S Rules by StudentsThe Electric Circuit And Kirchhoff’S Rules by Students
The Electric Circuit And Kirchhoff’S Rules by Studentskulachihansraj
 
Ten Commandment by Ms. S. Kumar
Ten Commandment by Ms. S. KumarTen Commandment by Ms. S. Kumar
Ten Commandment by Ms. S. Kumarkulachihansraj
 
Quadrilateral Family[1] Rashmi Kathuria
Quadrilateral Family[1] Rashmi KathuriaQuadrilateral Family[1] Rashmi Kathuria
Quadrilateral Family[1] Rashmi Kathuriakulachihansraj
 
Lord Ullins12 By Ms. Amardeep Kaur
Lord Ullins12 By Ms. Amardeep KaurLord Ullins12 By Ms. Amardeep Kaur
Lord Ullins12 By Ms. Amardeep Kaurkulachihansraj
 
Discipline By Ms Chandla
Discipline By Ms ChandlaDiscipline By Ms Chandla
Discipline By Ms Chandlakulachihansraj
 
Foreign exchange rate and its determination by Ms. Anita Babbar
Foreign exchange rate and its determination by Ms. Anita BabbarForeign exchange rate and its determination by Ms. Anita Babbar
Foreign exchange rate and its determination by Ms. Anita Babbarkulachihansraj
 
Business, Nature & Purpose By Ms. Bindu Dewan
Business, Nature & Purpose By Ms. Bindu DewanBusiness, Nature & Purpose By Ms. Bindu Dewan
Business, Nature & Purpose By Ms. Bindu Dewankulachihansraj
 

Plus de kulachihansraj (20)

What Is Internet made by Ms. Archika Bhatia
What Is Internet made by Ms. Archika BhatiaWhat Is Internet made by Ms. Archika Bhatia
What Is Internet made by Ms. Archika Bhatia
 
What Is A Network made by Ms. Archika Bhatia
What Is A Network made by Ms. Archika BhatiaWhat Is A Network made by Ms. Archika Bhatia
What Is A Network made by Ms. Archika Bhatia
 
Similarity By Ms. Rashmi Kathuria
Similarity By Ms. Rashmi KathuriaSimilarity By Ms. Rashmi Kathuria
Similarity By Ms. Rashmi Kathuria
 
Basic Terms(Circles)
Basic Terms(Circles) Basic Terms(Circles)
Basic Terms(Circles)
 
Unit cube Activity 2 by Ms. Rashmi Kathuria
Unit cube Activity 2 by Ms. Rashmi KathuriaUnit cube Activity 2 by Ms. Rashmi Kathuria
Unit cube Activity 2 by Ms. Rashmi Kathuria
 
unit cube Activity4 by Ms. Rashmi Kathuria
unit cube Activity4 by Ms. Rashmi Kathuriaunit cube Activity4 by Ms. Rashmi Kathuria
unit cube Activity4 by Ms. Rashmi Kathuria
 
Unit cube Activity 1 by Ms. Rashmi Kathuria
Unit cube Activity 1 by Ms. Rashmi KathuriaUnit cube Activity 1 by Ms. Rashmi Kathuria
Unit cube Activity 1 by Ms. Rashmi Kathuria
 
Unit-cubes Activity3 By Ms. Rashmi Kathuria
Unit-cubes Activity3 By Ms. Rashmi KathuriaUnit-cubes Activity3 By Ms. Rashmi Kathuria
Unit-cubes Activity3 By Ms. Rashmi Kathuria
 
Hybridization By Ms. Manjula Agarwal
Hybridization By Ms. Manjula AgarwalHybridization By Ms. Manjula Agarwal
Hybridization By Ms. Manjula Agarwal
 
Project Final Yogita Anand Kohli
Project Final Yogita Anand KohliProject Final Yogita Anand Kohli
Project Final Yogita Anand Kohli
 
Social religious reform movements in India By Ms. Seema Lal
Social religious reform movements in India By Ms. Seema LalSocial religious reform movements in India By Ms. Seema Lal
Social religious reform movements in India By Ms. Seema Lal
 
The Electric Circuit And Kirchhoff’S Rules by Students
The Electric Circuit And Kirchhoff’S Rules by StudentsThe Electric Circuit And Kirchhoff’S Rules by Students
The Electric Circuit And Kirchhoff’S Rules by Students
 
Ten Commandment by Ms. S. Kumar
Ten Commandment by Ms. S. KumarTen Commandment by Ms. S. Kumar
Ten Commandment by Ms. S. Kumar
 
Psychic Development
Psychic DevelopmentPsychic Development
Psychic Development
 
Quadrilateral Family[1] Rashmi Kathuria
Quadrilateral Family[1] Rashmi KathuriaQuadrilateral Family[1] Rashmi Kathuria
Quadrilateral Family[1] Rashmi Kathuria
 
Lord Ullins12 By Ms. Amardeep Kaur
Lord Ullins12 By Ms. Amardeep KaurLord Ullins12 By Ms. Amardeep Kaur
Lord Ullins12 By Ms. Amardeep Kaur
 
Healthydiet
HealthydietHealthydiet
Healthydiet
 
Discipline By Ms Chandla
Discipline By Ms ChandlaDiscipline By Ms Chandla
Discipline By Ms Chandla
 
Foreign exchange rate and its determination by Ms. Anita Babbar
Foreign exchange rate and its determination by Ms. Anita BabbarForeign exchange rate and its determination by Ms. Anita Babbar
Foreign exchange rate and its determination by Ms. Anita Babbar
 
Business, Nature & Purpose By Ms. Bindu Dewan
Business, Nature & Purpose By Ms. Bindu DewanBusiness, Nature & Purpose By Ms. Bindu Dewan
Business, Nature & Purpose By Ms. Bindu Dewan
 

Dernier

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Dernier (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Stacks & Queues By Ms. Niti Arora

  • 1. Let’s learn TACKS & UEUES for CLASS XII( C++) SENIOR SECONDARY GROUP Presented By : NITI ARORA
  • 2. STACKS AND QUEUES
  • 3.
  • 4. A mathematical and logical model of data is known as Data Structure .   Primitive data structure : The data structure, which is available in the compiler, is known as a primitive data structure . Non-primitive data structure : The data structure, which is not available in the compiler, is known as non-primitive data structure .   DATA STRUCTURE: INTRODUCTION
  • 5.   Linear Data Structure : The data structure in which each element has access to maximum of one predecessor element and maximum of one successor element is known as linear data structure . Example: Stack, Queue, etc . Non-linear Data Structure : The data structure in which each element can access any number of predecessor elements and any number of successor elements is known as Non-linear data structure . Example: Tree, Graphs, etc .   DATA STRUCTURE: INTRODUCTION
  • 6. Static Data Structure: The data structure in which the number of elements is fixed, is known as Static Data Structure . Example: Arrays Dynamic Data Structure: The data structure in which the number of elements is not fixed, is known as Dynamic Data Structure . Example: Linked List. TYPES OF DATA STRUCTURE
  • 7. It is a static data structure . It is a homogeneous collection of data. The elements in the array are stored on consecutive memory locations. Array is also known as a subscripted variable, e.g., A[i] is i th element of the array A. ARRAY
  • 8. STACK It is a non-primitive linear data structure in which insertion and deletion of elements takes place from only one end , known as top. It is a non-primitive linear data structure in which insertion and deletion of elements takes place from two opposite ends rear and front respectively. QUEUE
  • 9. STACKS Stacks is LIFO (Last In First Out) structure and physically can be implemented as an array or as a linked list. Stack, when implemented as an array is functionally same as any other array except that here, adding an element and deletion is done from the same direction just like a pile of books.
  • 10.
  • 11. STACK A stack is a list in which insertion and deletion takes place only at one end called top. Thus, called LIFO. Representation of STACK Each one of the above has one open and one close end and data movement takes place from open end . data4 TOP data3 data2 data1 data2 data1 data3 data4 TOP TOP data4 data3 data2 data1 data1 data2 data3 data4 TOP
  • 12.
  • 13. STACKS The fundamental operations that can be performed on stack are PUSH and POP . When element is added on the stack top is called PUSH . And When Data is removed from the stack top, the operation is called POP.
  • 14. STACK The stack operation can be explained as follows: Stack operation Content of array Push(a) a Push(b) ba Push( c) cba Pop() ba Pop() a Push (a) a b a Push(b) b a C Push( c) b a Pop( c) a Pop(b)
  • 15.
  • 16. Linear Stack int S[5]; When PUSH is selected, TOP is incremented, And data is added at that subscript location When POP is selected, TOP is decremented, And data is removed from that subscript location Stack array int TOP; To hold address of location where data is inserted or deleted
  • 17.
  • 18.
  • 19. Lets see this using a program Program Code for the Same is Click here to execute program Click here to see program code
  • 20. A variable which holds an address of a memory location of another variable is known as a Pointer Variable (or only pointer). Example int amt, *p; amt Requires 2 bytes 0x8ffebab4 *P Requires 2 bytes Pointer P holds address of amt POINTER     900     0x8ffebab4
  • 21. NEW operator in C++ returns the address of a block of unallocated bytes (depending on data type a pointer pointing to). DELETE operator in C++ reverses the process of new operator, by releasing the memory location from a pointer. It de allocates memory assigned by NEW. DYNAMIC ALLOCATION
  • 22. A pointer, which stores the address of struct type data, is known as Pointer to structure. struct abc { int X,Y; }; struct *g=new abc; Holds address of dynamic object of struct abc   G   0x8ff134ab G->X 0x8ff134ab G->X G->Y LINK LIST To allocate dynamic allocation and store address in point g    
  • 23. struct STACK // structure for stack { int data; STACK *link; }; struct *TOP; LINK STACK To hold address of First node of the list TOP pointer to holds address of dynamic objects of link stack. As we push a node TOP element get shifted and new node becomes first node. LIFO implementation every new node becomes first node. When we pop Top node is deleted and next node becomes first node.
  • 24. Lets see working of Linked stack * TOP * Temp NULL 0x8ffab2e6 A new memory is allocated and address is stored in temp X NULL data link 0x8ffab2e6 Top = Temp Top will hold address of new location * TOP 0x8ffab2e6 Thus, TOP will have this address. Push operation Initially top is assigned NULL Temp holds address of new location
  • 25. Cont….. *TOP * Temp 0x8ffab2e6 0x8ffab2e8 Another new memory is allocated to an object Y data link 0x8ffab2e8 * TOP 0x8ffab2e8 X NULL data link 0x8ffab2e6 temp-> link = Top Top=temp 0x8ffab2e6 Now TOP is TOP will get shifted Y becomes first node X becomes second node
  • 26. Cont….. * TOP * Temp 0x8ffab2e8 0x8ffab2e8 An object is deleted from top Y data link 0x8ffab2e8 Thus Top will be * TOP 0x8ffab2e6 X NULL data link Temp=TOP TOP=TOP->link 0x8ffab2e6 delete temp (to release memory) 0x8ffab2e6 TOP will get shifted X becomes first node Y will be released POP operation
  • 27. Lets see this using a program Program Code for the Same is Click here to execute program Click here to see program code
  • 28.
  • 29.
  • 30. Queue A Queue is a data structure in which insertion is done at the end and deletion is done from the front of queue. It is FIFO . Representation of Queue Each one of the above has two open end Front and Rear. Insertion is done from Rear and deletion form Front Rear Front Front Rear Front Rear Front Rear data4 data3 data2 data2 data3 data4 data4 data3 data2 data2 data3 data4
  • 31.
  • 32. QUEUE The fundamental operations that can be performed on Queue are Insert and Delete . When element is added on the Queue Front is called Insert . And When Data is removed from the Queue Rear, the operation is called Delete.
  • 33. QUEUE The Queue operation can be explained as follows: Queue operation Content of array Insert(a) Front=0 Rear=0 Insert(b) Front=0 Rear=1 Insert( c) Front=0 Rear=2 Delete() Front=1 Rear=2 Delete() Front=2 Rear=2 If we try to insert Overflow occurs Though first two cells are empty a b a c b a c b c
  • 34. Linear Queue int Q[5]; When INSERT is selected, Rear is incremented, And data is added at that subscript location When DELETE is selected, Front is decremented, And data is removed from that subscript location Queue array int Front, Rear; To hold address of location where data is inserted or deleted
  • 35.
  • 36. Lets see working of LINEAR QUEUE Insert 7 Insert 20 Insert 14 OVERFLOW QUEUE is full Front rear rear rear Front Front Rear is incremented Rear++ 10 9 8 10 9 8 7 10 9 8 7 20
  • 37. Lets see working of Queue as an array Delete Delete Underflow occurs when QUEUE is empty Rear Front Rear Rear Front Front Front is incremented Front++ 10 9 8 7 20 9 8 7 20 8 7 20
  • 38. Lets see this using a program Program Code for the Same is Click here to execute program Click here to see program code
  • 39. struct QUEUE // structure for QUEU { int data; QUEUE *link; }; struct *Front,*Rear; LINKED QUEUE To hold address of First and Last node of the list Front and Rear pointer to holds address of dynamic objects of link stack. As we insert a node Rear element get shifted and new node becomes next node. FIFO implementation every new node added at end. When we Delete Front node is deleted and next node becomes first node.
  • 40. Lets see working of Linked Queue * Front * Rear * Temp NULL NULL 0x8ffab2e6 A new memory is allocated and address is stored in temp X NULL data link 0x8ffab2e6 Front=Rear = Temp Front and Rear will hold address of First location * Front * Rear 0x8ffab2e6 0x8ffab2e6 Thus, Front and Rear will have this address . Insert operation Initially Front and Rear is assigned NULL Temp holds address of new location
  • 41. Cont….. *Front * Rear * Temp 0x8ffab2e6 0x8ffab2e6 0x8ffab2e8 Another new memory is allocated to an object X data link 0x8ffab2e6 * Rear 0x8ffab2e8 Y NULL data link 0x8ffab2e8 temp-> link = Rear Rear=temp 0x8ffab2e8 Now Rear is Rear will get shifted Y becomes Last node
  • 42. Cont….. * Front * Rear * Temp 0x8ffab2e6 0x8ffab2e8 0x8ffab2e6 An object is deleted from Front X data link 0x8ffab2e6 Thus Front will be * Front 0x8ffab2e8 Y NULL data link Temp=Front Front=Front->link 0x8ffab2e8 delete temp (to release memory) 0x8ffab2e8 Front will get shifted Y becomes first node X will be released Delete operation
  • 43. Lets see this using a program Program Code for the Same is Click here to execute program Click here to see program code
  • 44. CIRCULAR QUEUE The fundamental operations that can be performed on Circular Queue are Insert and Delete . When overflow occurs though the free cells are available, Rear reaches ends Circular Queue is implemented to avoid this drawback. In Circular Queue as soon as Rear reaches maximum it should reset to 0.
  • 45. QUEUE The Queue operation can be explained as follows: Queue operation Content of array Insert(a) Front=0 Rear=0 Insert(b) Front=0 Rear=1 Insert( c) Front=0 Rear=2 Delete() Front=1 Rear=2 Insert (d) Front=2 Rear=0 Overflow occurs only when Array is FULL. Rear moves to 0 if array is empty a b a c b a c b c d
  • 46. Lets see this using a program Program Code for the Same is Click here to execute program Click here to see program code
  • 47. Do you have any QUESTIONS ?
  • 48.