Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
16 views
Data Structure - Stack and Queue
Uploaded by
nikhilran907
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 10. Data Structure_ Stack and Queue For Later
Download
Save
Save 10. Data Structure_ Stack and Queue For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
16 views
Data Structure - Stack and Queue
Uploaded by
nikhilran907
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 10. Data Structure_ Stack and Queue For Later
Carousel Previous
Carousel Next
Save
Save 10. Data Structure_ Stack and Queue For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 9
Search
Fullscreen
Unit i: Computational Thinking ramming -2 Visit to website: learnpythondcbse.com Chapter-10 Data Structure - II Stack and Queue 1 Stack 2 Example: Implementing Stack In Python 3 Queue 4 Example: Implementation of Queue Page ofVisit to webs O Data Structure - II Linear data structures are collections of components arranged in a straight line > Astack is a data structure that keeps objects in Last-In-First-Out (LIFO) order ees oe > Objects are added to the top of the stack > Only the top of the stack can Push a new Pop a book be accessed hod ‘book on top rnp Asta of ack > Apile of books or a stack of (inaccessible) four books dinner plates can be thought of examples of stacks. It has three primitive operations: e Push: Add an element to the stack * Pop: Remove an element from the stack © Peek: Get the topmost element of the stack In Python, a stack is implemented using a list object. © To push an item in the stack, use the list function append list.append{(item) © To pop an item in the stack, use the list function pop list.pop() To get the top most item in the stack, write list{-1] Page 20f9Uni ‘omputational Thinking and Programming -2 File Est Formet Run Options Window Help # Created By: learnpython4cbse.com B # Stack using List # Function to check Stack is empty or not def isEmpty (Lst) if len(Lst) return 1 else: return 0 # Function to add (PUSH) elements in Stack def Push_Stack(Lst,val): Lst append (val) top=len (Lst) -1 # Function to Delete (POP) elements in Stack def Pop_Stack(Lst): if isempty (Lst) : return "UnderFlow" else: ele=Lst.pop() if len(Lst) top=None else: top=len (Lst)-1 return ele # Function to Display Top element of Stack def Peek _Stack(Lst): if iszmpty (ist): return "UnderFlow" else: top=len (Lst)-1 return Lst[top] Ln37 Cok 23 Page 3.0f9 ‘Visit to website: learnpythondcbse.com Chapter-10 Data Structure - IIUnit I: Computational Thinking and! Visit to website: learnpythondcbse.com gramming -2 Chapter-10 Data Structure - II [Sk yD Fie Eat Format fun Opbons_vindow “Help # Function to Display elements of Stack F| cf Display_Stack(Lst) ip isBapty (ist) print ("No Item to Display.....") else: fen (Lst) -1 print (" (TOP) ", en wails tp=0: print (ist (tpl, "<-',end=" ") tp -=1 print Q) » # Driver function Jost main(): List Top while Truet print) print ("##### STACK OPERATIONS #####") print ("1. PUSH- Insertion") print ("2. POP- Deletion") print ("3. PEEK- Show Top Element") . print ("4. DISPLAY - Show Stack") print ("0. EXIT") choice=int (input ("Enter Your Choic: if choice==1: Element=int (input ("Enter El Push_Stack (List, Element) elif choice==2: Element=Pop_stack (List) + if Element=="UnderFlow": print ("stack is Empty") else: print ("Deleted Element was " Element) elif choice==3: Element=Peek_stack (bist) Lf Blement=="UnderFlow": print ("stack is Empty") else: print ("Top Element : ",Element) e1if choice: Display_stack (List) elif choice: print ("Good Luck. break main () | ” Page dofUnit I: Computational Thinking and Programming -2 ‘Visit to website: learnpythondcbse.com Chapter-10 Data Structure - II OUTPUT ‘itt STACK OPERATIONS ###t 1. PUSH- Insertion 2. POP- Deletion 3. PEEK- Show Top Element 4, DISPLAY - Show Stack 0. EXIT Enter Your Choice: 1 Enter Element to Push: 20 ‘uit STACK OPERATIONS sits 1. PUSH- Insertion 2. POP- Deletion 3. PEEK- Show Top Element 4, DISPLAY - Show Stack 0. EXIT Enter Your Choice: 1 Enter Element to Push: 30 ‘itt STACK OPERATIONS ##s#t 1. PUSH- Insertion 2. POP- Deletion 3. PEEK- Show Top Element 4. DISPLAY - Show Stack 0. EXIT Enter Your Choice: 1 Enter Element to Push: 88 ‘Hitt STACK OPERATIONS itis 1. PUSH- Insertion 2. POP- Deletion 3, PEEK- Show Top Element 4, DISPLAY - Show Stack 0. EXIT Enter Your Choice: 4 [TOP] 88 <- 30 <- 20 <- ‘aititttt STACK OPERATIONS ###it 1. PUSH- Insertion 2. POP- Deletion 3. PEEK- Show Top Element 4, DISPLAY - Show Stack 0. EXIT Enter Your Choice: 3 Top Element: 88 ‘uit STACK OPERATIONS sits 1. PUSH- Insertion 2. POP- Deletion 3. PEEK- Show Top Element 4, DISPLAY - Show Stack 0. EXIT Enter Your Choice: 2 Deleted Element was: 88 ‘uit STACK OPERATIONS sits 1. PUSH- Insertion 2. POP- Deletion 3, PEEK- Show Top Element 4, DISPLAY - Show Stack 0. EXIT Enter Your Choice: 4 [TOP] 30 <- 20 <- itt STACK OPERATIONS ####t 1. PUSH- Insertion 2. POP- Deletion 3. PEEK- Show Top Element 4, DISPLAY - Show Stack 0. EXIT Enter Your Choice: 0 GoOd Lucksrvsree Page Sof 9Queues are data structures that follow the First In First Out (FIFO) i.e. the first element that is added to the queue is the first one to be removed. > Waiting in line Real life examples v of queue > Waiting on hold for tech we ) support ) ) ) ) > Applications related to New element is added to the rear Computer Science of the queue > Round robin scheduling > Key board buffer QUEUE OPERATIONS: > Peek : getting first value of QUEUE i.e. of FRONT position. Queue[Front] _ # Front is an int storing index of first element of queue > Enqueue: addition of new item in QUEUE at REAR position. e.g. Queue. append(Item) > Dequeue: removal of item from the beginning of QUEUE. e.g. Queue.pop(0) Page 6 of 9Uni ‘omputational Thinking and Programming -2 Visit to website: learnpythondcbse.com Chapter-10 Data Structure - II File Edit Format Run Options Window Help \|I# Created By: learnpython4cbse.com I || # Queue using List # Function to check Queue is empty or not def isEmpty (qLst): if len(qLst return 1 else: return 0 # Function to add elements in Queue def Enqueue (qLst, val): qist . append (val) if len(qLst! front=rea: else: rear=len (qLst)-1 # Function to Delete elements in Queue def Dqueue (qLst) : if isempty(qust) : return "UnderFlow" else: | val = qhst.pop(0) y if len (qust)= j front=rear=None return val # Function to Display top element of Queue def Peek(qLst) : if isempty(qLst) : return "UnderFlow" else: front=0 return qLst [front] Und Cobo Page 7 of 9Unit I: Computational Thinking and! Visit to website: learnpythondcbse.com Chapter-10 Data Structure - II (se Ques - Dvn Sm Fie Eat Fomat fon Opens Window Hep ¥ Function to Display elements of queue - dof Display (gist): | if isimpty(qhst) + print ("No Ttem to Dispay in Queue. els: tp = len(qust)-1 print (* [FRONT: front = 0 i = front rear = len(qhst)-1 while (i
You might also like
Data Structure - Stack and Queue
PDF
No ratings yet
Data Structure - Stack and Queue
9 pages
Data Structure Stack and Queue
PDF
No ratings yet
Data Structure Stack and Queue
9 pages
Data Structures
PDF
No ratings yet
Data Structures
7 pages
XII Data Structure Reading Material
PDF
No ratings yet
XII Data Structure Reading Material
4 pages
CHAPTER 10_DATA STRUCTURE-II_STACKS AND QUEUES notes for computer science class 12
PDF
No ratings yet
CHAPTER 10_DATA STRUCTURE-II_STACKS AND QUEUES notes for computer science class 12
9 pages
Chapter 16 Stack and Queues Part2: Dr. Bernard Chen PH.D
PDF
No ratings yet
Chapter 16 Stack and Queues Part2: Dr. Bernard Chen PH.D
30 pages
DS Unit2
PDF
No ratings yet
DS Unit2
34 pages
CSCI2320 Chapter 16 Part2
PDF
No ratings yet
CSCI2320 Chapter 16 Part2
30 pages
Data Structure
PDF
No ratings yet
Data Structure
5 pages
XIIComp - SC - Data Structures
PDF
No ratings yet
XIIComp - SC - Data Structures
19 pages
Dsu QB
PDF
No ratings yet
Dsu QB
23 pages
Chapter 2
PDF
No ratings yet
Chapter 2
3 pages
Computer Science: Data-Structures: Lists, Stacks, Queues
PDF
No ratings yet
Computer Science: Data-Structures: Lists, Stacks, Queues
18 pages
Data Structures Notes
PDF
No ratings yet
Data Structures Notes
10 pages
Stacks Preeti Arora
PDF
100% (1)
Stacks Preeti Arora
6 pages
Data Structures 3
PDF
No ratings yet
Data Structures 3
29 pages
CC104 Chapter 4 Queues
PDF
No ratings yet
CC104 Chapter 4 Queues
24 pages
2.2.2 Circular Queue
PDF
No ratings yet
2.2.2 Circular Queue
26 pages
CSE601 - Data Structure and Algorithm
PDF
No ratings yet
CSE601 - Data Structure and Algorithm
230 pages
8 - 9 Data Structure Stake Queue 1
PDF
No ratings yet
8 - 9 Data Structure Stake Queue 1
8 pages
Stack-and-Queue
PDF
No ratings yet
Stack-and-Queue
11 pages
Queues
PDF
No ratings yet
Queues
64 pages
DS Study Material Module 1
PDF
No ratings yet
DS Study Material Module 1
9 pages
Queue
PDF
No ratings yet
Queue
6 pages
Class XII (As Per CBSE Board) : Computer Science
PDF
No ratings yet
Class XII (As Per CBSE Board) : Computer Science
16 pages
APznzaZ2xYUY2XWMEdYak9wlPDw4Dube1VP1RTGrOngFrUXos6xg9eRIIQucyYtUbrMaG BM9ZGcX4uTFodAsLj9CD0j5AL7LrnP5v4Zwv2KarfGzpTpEf2tNFDUH2Rsdx0xbvdGeXXKJYKBMAww27U 0lZ-Sx3YcgCRG1hd0pYyDZYbHjPuj0y SpFI4m8iycvo GwLC3bcpuYBq3kg42gr4
PDF
No ratings yet
APznzaZ2xYUY2XWMEdYak9wlPDw4Dube1VP1RTGrOngFrUXos6xg9eRIIQucyYtUbrMaG BM9ZGcX4uTFodAsLj9CD0j5AL7LrnP5v4Zwv2KarfGzpTpEf2tNFDUH2Rsdx0xbvdGeXXKJYKBMAww27U 0lZ-Sx3YcgCRG1hd0pYyDZYbHjPuj0y SpFI4m8iycvo GwLC3bcpuYBq3kg42gr4
4 pages
Dataa Structures Cs
PDF
No ratings yet
Dataa Structures Cs
16 pages
Stacks and Queues in Detail
PDF
No ratings yet
Stacks and Queues in Detail
5 pages
IDS - Unit-4.pptx (3)
PDF
No ratings yet
IDS - Unit-4.pptx (3)
80 pages
DSA Project
PDF
No ratings yet
DSA Project
10 pages
009.1 Data Structure- II
PDF
No ratings yet
009.1 Data Structure- II
14 pages
Stacks & Queues: By: Hradesh Kumar
PDF
No ratings yet
Stacks & Queues: By: Hradesh Kumar
40 pages
Lecture3_Stacks and Queues
PDF
No ratings yet
Lecture3_Stacks and Queues
40 pages
Data Structure Using in Python
PDF
No ratings yet
Data Structure Using in Python
32 pages
Lecture 2.2.2 Circular Queue
PDF
No ratings yet
Lecture 2.2.2 Circular Queue
26 pages
Ch-3-Queue
PDF
No ratings yet
Ch-3-Queue
24 pages
Queue
PDF
No ratings yet
Queue
20 pages
Queue
PDF
No ratings yet
Queue
61 pages
Stack and Queue
PDF
No ratings yet
Stack and Queue
28 pages
Chapter 8
PDF
No ratings yet
Chapter 8
5 pages
A Continuation of DSA RTU Part 2
PDF
No ratings yet
A Continuation of DSA RTU Part 2
139 pages
17 05 2024 DSA With Python For Student
PDF
No ratings yet
17 05 2024 DSA With Python For Student
22 pages
Unit 2 - QUEUE
PDF
No ratings yet
Unit 2 - QUEUE
30 pages
Queue
PDF
No ratings yet
Queue
55 pages
PLDS UNIT 5 (3)
PDF
No ratings yet
PLDS UNIT 5 (3)
18 pages
Aim: Write A Program To Implement Stack & Queue. Theory
PDF
No ratings yet
Aim: Write A Program To Implement Stack & Queue. Theory
6 pages
4 Queue: in This
PDF
No ratings yet
4 Queue: in This
14 pages
2.2 Queue Uing Array & Linked List
PDF
No ratings yet
2.2 Queue Uing Array & Linked List
28 pages
exp4
PDF
No ratings yet
exp4
4 pages
Stack and Queue
PDF
No ratings yet
Stack and Queue
16 pages
Vinay SE-05 - 46 Exp-1
PDF
No ratings yet
Vinay SE-05 - 46 Exp-1
21 pages
2.4 Queue Uing Array & Linked List.
PDF
No ratings yet
2.4 Queue Uing Array & Linked List.
28 pages
4 Stacks Queues
PDF
No ratings yet
4 Stacks Queues
48 pages
FALLSEM2024-25_BCSE202L_TH_VL2024250101794_2024-08-01_Reference-Material-V
PDF
No ratings yet
FALLSEM2024-25_BCSE202L_TH_VL2024250101794_2024-08-01_Reference-Material-V
14 pages
Queues ADT
PDF
No ratings yet
Queues ADT
31 pages
DATA-STRUCTURES Note
PDF
No ratings yet
DATA-STRUCTURES Note
11 pages
DSA Unit 3
PDF
No ratings yet
DSA Unit 3
22 pages
Test - 26-12-2023
PDF
No ratings yet
Test - 26-12-2023
10 pages
Dsmaterial 4
PDF
No ratings yet
Dsmaterial 4
5 pages