Skip to main content
Open navigation menu
Close suggestions
Search
Search
en
Change Language, English
Upload
Sign in
Sign in
0 ratings
0% found this document useful (0 votes)
9 views
9 pages
Data Structure - Stack and Queue
Uploaded by
FF gaming
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
Save
Save 10. Data Structure_ Stack and Queue For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
9 views
9 pages
Data Structure - Stack and Queue
Uploaded by
FF gaming
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
Go to previous items
Download
Save
Save 10. Data Structure_ Stack and Queue For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
Go to next items
Download
Save 10. Data Structure_ Stack and Queue For Later
Share
More options
Fullscreen
Unit I: Computational Thinking and Programming -2 Visit to webs snpythonacbse com (Oo Ty epee RO PL Le eat Ceia ltd eee OE Stack and Queue Brent 1 Stack 2 Example: Implementing Stack In Python 3 Queue 4 Example: Implementation of Queue Page 1of9Visit to webs [Link] O Data Structure - II Linear data structures are collections of components arranged ina 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 be accessed Push anew Pop abok Bottom of book on top mop Asstack of lack > Apile of books or a stack of (inaccessible) four books dinner plates can be thought of examples of stacks. It has three primitive operations: © 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 [Link]{(item) To pop an item in the stack, use the list function pop [Link]() © To get the top most item in the stack, write list{-1] Page 20f9Unit I: Computational Thinking and Programming -2 Chapter-10 Data Structure - II ‘Visit to website: [Link] File Et Formet Run Options Window Help # Created By: [Link] # Stack using List # Function to check Stack is empty or not def isEmpty (Lst): if len(Lst)==0: 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=[Link]() if len(Lst top=None else: top=len (Lst)-1 return ele # Function to Display Top element of Stack def Peek Stack(Lst): if isEmpty (Lst): return "UnderFlow" else: top=len(Lst)-1 return Lst [top] Ln37 Cok 23 Page 30f9Unit I: Computational Thinking and Programming -2 [a etry Doin fie ae format fin Oman window Hep 4 Function to Display elenents of Stack Joef Display_stack(ist) Sf istmpey (st) Print ("NO Tem to Display.....") else: fen (Lst) -1 PEint (" (T0P]", en wails tp=0: print (ist [tp], "<-',end=" ") tp - print () » # Driver function Jost main(): List Top wile 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, Bement) elif choice==2: Element=Pop_stack (List) if Element=="UnderFlow": print ("stack is Empty") else: print ("Deleted Element was elif choice==3: Element=Peek stack (List) if Blement=="UnderFlow" print ("stack is Empty") else: print ("top Element : ",Element) elif choice: Display Stack (List) elif choice= print ("Good Luck. break ” main () Page 40f9 Chapter-10 Data Structure - II " Element) ‘Visit to website: [Link]Unit I: Computational Thinking and Programming -2 ‘Visit to website: [Link] Chapter-10 Data Structure - II OUTPUT sittttt STACK OPERATIONS ##t#it 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 ‘uitttih STACK OPERATIONS #ititis 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 #ttittt 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 <- ‘atttttt 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 ‘uittih STACK OPERATIONS #iitit 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 ‘uittih STACK OPERATIONS #iitit 1. PUSH- Insertion 2. POP- Deletion 3. PEEK- Show Top Element 4, DISPLAY - Show Stack 0. EXIT Enter Your Choice: 4 [TOP] 30 <- 20 <- suits STACK OPERATIONS ##8##t 1. PUSH- Insertion 2. POP- Deletion 3. PEEK- Show Top Element 4, DISPLAY - Show Stack 0. EXIT Enter Your Choice: 0 Good Luck, Page 50f 8Visit to webs [Link] O Data Structure - II Queues 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 aT of queue > Waiting on hold for tech wn ) ve hhh > 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. [Link](0) Page 6 of 9Unit I: Computational Thinking and Programming -2 Visit to website: [Link] Chapter-10 Data Structure - II File Edit Format Run Options Window Help \||# Created By: [Link] il || # 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 (qhst) : return "UnderFlow™ else: | val = [Link](0) y if len(qbst) = \ 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 70f9‘Visit to website: [Link] Unit I: Computational Thinking and Programming -2 Chapter-10 Data Structure - II (se Que y Dina mun Fie Eat Fomat fn Opbens Window Hep ¥ Function to Display elements of queue def Display (qLst): if isBmpty(qbst) + print ("No Ttem to Dispay in Queue. els: tp = len(qust)-1 print (* [FRONT: front = 0 i= front rear = len(qust)-1 while (i
You might also like
Data Structure - Stack and Queue
PDF
No ratings yet
Data Structure - Stack and Queue
9 pages
Python Stack and Queue Implementation
PDF
No ratings yet
Python Stack and Queue Implementation
9 pages
Stack and Queue Data Structures Guide
PDF
No ratings yet
Stack and Queue Data Structures Guide
9 pages
Python Stack Program for Class 12
PDF
No ratings yet
Python Stack Program for Class 12
16 pages
Linear Lists and Data Structures Overview
PDF
No ratings yet
Linear Lists and Data Structures Overview
4 pages
Real-Life Stack Examples and Usage
PDF
No ratings yet
Real-Life Stack Examples and Usage
4 pages
Class 12 Data Structures: Stacks & Queues
PDF
100% (1)
Class 12 Data Structures: Stacks & Queues
10 pages
Linear Data Structures Overview
PDF
No ratings yet
Linear Data Structures Overview
13 pages
Data Structures: Stacks, Queues, Linked Lists
PDF
No ratings yet
Data Structures: Stacks, Queues, Linked Lists
89 pages
Stack and Queue Data Structures Explained
PDF
No ratings yet
Stack and Queue Data Structures Explained
7 pages
1.4.2 Data Structures
PDF
No ratings yet
1.4.2 Data Structures
23 pages
Linear Data Structures Overview
PDF
No ratings yet
Linear Data Structures Overview
110 pages
Understanding Stacks and Queues
PDF
No ratings yet
Understanding Stacks and Queues
10 pages
Data Structures in Python: Linked List, Stack, Queue
PDF
No ratings yet
Data Structures in Python: Linked List, Stack, Queue
17 pages
Data Structures: Arrays and Stacks in C
PDF
No ratings yet
Data Structures: Arrays and Stacks in C
18 pages
Data Structure Implementation Guide
PDF
No ratings yet
Data Structure Implementation Guide
39 pages
Stacks and Queues in Python
PDF
No ratings yet
Stacks and Queues in Python
14 pages
Stacks and Queues in Data Structures
PDF
No ratings yet
Stacks and Queues in Data Structures
33 pages
Linked Lists, Stacks, and Queues Explained
PDF
No ratings yet
Linked Lists, Stacks, and Queues Explained
30 pages
Day 6 - Stack & Queue
PDF
No ratings yet
Day 6 - Stack & Queue
22 pages
Data Structures: Stacks and Queues Guide
PDF
No ratings yet
Data Structures: Stacks and Queues Guide
16 pages
DS Manual AIML - DS
PDF
No ratings yet
DS Manual AIML - DS
32 pages
Stacks and Queues: Data Structures Explained
PDF
No ratings yet
Stacks and Queues: Data Structures Explained
49 pages
Stacks Queue
PDF
No ratings yet
Stacks Queue
11 pages
Stack and Queue Data Structures Guide
PDF
No ratings yet
Stack and Queue Data Structures Guide
23 pages
Stack and Queue Data Structures Guide
PDF
No ratings yet
Stack and Queue Data Structures Guide
11 pages
Stacks and Queues in Data Structures
PDF
No ratings yet
Stacks and Queues in Data Structures
3 pages
Data Structures: Stacks, Queues, Hashing
PDF
No ratings yet
Data Structures: Stacks, Queues, Hashing
80 pages
Data Structures in Python for Class 12
PDF
No ratings yet
Data Structures in Python for Class 12
16 pages
DS Lec 3 (Stacks - Queues)
PDF
No ratings yet
DS Lec 3 (Stacks - Queues)
23 pages
Data Structures: Stacks, Queues, Lists
PDF
No ratings yet
Data Structures: Stacks, Queues, Lists
35 pages
Understanding Data Structures and Types
PDF
No ratings yet
Understanding Data Structures and Types
22 pages
Stacks and Queues: Data Structures Explained
PDF
No ratings yet
Stacks and Queues: Data Structures Explained
40 pages
Data Structure Unit 3
PDF
No ratings yet
Data Structure Unit 3
10 pages
Core Data Structures in Computer Science
PDF
No ratings yet
Core Data Structures in Computer Science
37 pages
Stack and Queue Data Structures Explained
PDF
No ratings yet
Stack and Queue Data Structures Explained
5 pages
Python Data Structures: Stacks & Queues
PDF
No ratings yet
Python Data Structures: Stacks & Queues
29 pages
Unit 3 Queue
PDF
No ratings yet
Unit 3 Queue
40 pages
Overview of Data Structures and Operations
PDF
No ratings yet
Overview of Data Structures and Operations
20 pages
Understanding Data Structures: Stacks & Queues
PDF
No ratings yet
Understanding Data Structures: Stacks & Queues
25 pages
Understanding Data Structures and Types
PDF
No ratings yet
Understanding Data Structures and Types
8 pages
Unit 2 - Stacks & Queues
PDF
No ratings yet
Unit 2 - Stacks & Queues
32 pages
Dsa in Python
PDF
No ratings yet
Dsa in Python
6 pages
Understanding Stacks and Queues
PDF
No ratings yet
Understanding Stacks and Queues
30 pages
Cormen Introduction To Algorithms - LEFT PORTION
PDF
No ratings yet
Cormen Introduction To Algorithms - LEFT PORTION
5 pages
Data Structure
PDF
No ratings yet
Data Structure
16 pages
4A Introduction To Stacks and Queues
PDF
No ratings yet
4A Introduction To Stacks and Queues
20 pages
Stacks and Queues: Data Structures Explained
PDF
No ratings yet
Stacks and Queues: Data Structures Explained
35 pages
Stack and Queue
PDF
No ratings yet
Stack and Queue
14 pages
1.data Structures in Python-Stack
PDF
No ratings yet
1.data Structures in Python-Stack
18 pages
Understanding Data Structures in Python
PDF
No ratings yet
Understanding Data Structures in Python
14 pages
Unit2 Notes
PDF
No ratings yet
Unit2 Notes
5 pages
Understanding Stack Data Structure
PDF
No ratings yet
Understanding Stack Data Structure
10 pages
C Programming Stack and Queue Operations
PDF
No ratings yet
C Programming Stack and Queue Operations
10 pages
Understanding Stacks and Queues in Data Structures
PDF
No ratings yet
Understanding Stacks and Queues in Data Structures
83 pages
Understanding Stacks and Queues in Data Structures
PDF
No ratings yet
Understanding Stacks and Queues in Data Structures
60 pages
Python Menu-Driven Stacks & Queues
PDF
No ratings yet
Python Menu-Driven Stacks & Queues
8 pages
Python Notes for Beginners PDF
PDF
80% (10)
Python Notes for Beginners PDF
90 pages
Data Structures Overview and Examples
PDF
92% (24)
Data Structures Overview and Examples
90 pages
Java Programming Notes for B.Tech 2nd Sem
PDF
100% (9)
Java Programming Notes for B.Tech 2nd Sem
127 pages
Let Us C Book
PDF
100% (6)
Let Us C Book
357 pages
Free Handwritten Python Notes PDF
PDF
94% (36)
Free Handwritten Python Notes PDF
186 pages
Pipelining and Vector Processing Overview
PDF
83% (12)
Pipelining and Vector Processing Overview
37 pages
C Programming Basics and Data Types
PDF
100% (12)
C Programming Basics and Data Types
147 pages
Digital Electronics Question Bank 2024
PDF
100% (14)
Digital Electronics Question Bank 2024
12 pages
Python Programming Examples PDF
PDF
90% (10)
Python Programming Examples PDF
105 pages
Indian Psychology and Moksha Insights
PDF
No ratings yet
Indian Psychology and Moksha Insights
25 pages
C Programming Exercises and Solutions
PDF
87% (15)
C Programming Exercises and Solutions
26 pages
Let Us Python by Yashavant Kanetkar
PDF
89% (35)
Let Us Python by Yashavant Kanetkar
429 pages
Handwritten COA Notes PDF Download
PDF
89% (9)
Handwritten COA Notes PDF Download
152 pages
DSA Hand Written Notes
PDF
89% (18)
DSA Hand Written Notes
32 pages
Learn C Programming
PDF
100% (11)
Learn C Programming
169 pages
Complete Guide to Data Structures
PDF
75% (4)
Complete Guide to Data Structures
96 pages
RD Sharma Class 11 Maths PDF Guide
PDF
86% (119)
RD Sharma Class 11 Maths PDF Guide
728 pages
DSA in C Notes Handwritten
PDF
92% (13)
DSA in C Notes Handwritten
111 pages
Deadlock Handling Methods in OS
PDF
No ratings yet
Deadlock Handling Methods in OS
16 pages
OS UNIT-4 (Memory Management)
PDF
No ratings yet
OS UNIT-4 (Memory Management)
13 pages
C Programming Basics and Development Guide
PDF
83% (18)
C Programming Basics and Development Guide
179 pages
140 Basic Python Programs for Beginners
PDF
84% (19)
140 Basic Python Programs for Beginners
96 pages
Durgasoft Python Notes Overview
PDF
85% (66)
Durgasoft Python Notes Overview
367 pages
Operating System Handwritten Notes of Module 1,2,3,4,5
PDF
94% (17)
Operating System Handwritten Notes of Module 1,2,3,4,5
78 pages
Encoders and Decoders in Digital Logic
PDF
100% (3)
Encoders and Decoders in Digital Logic
15 pages
DBMS Handwritten Notes Q1j2as
PDF
100% (5)
DBMS Handwritten Notes Q1j2as
56 pages
C Programming Fundamentals Notes
PDF
100% (2)
C Programming Fundamentals Notes
52 pages
Python Class 11 Full Book Sumita Arora Good Quality Print
PDF
86% (288)
Python Class 11 Full Book Sumita Arora Good Quality Print
530 pages
Data Structures Notes for 3rd Sem BCA
PDF
60% (5)
Data Structures Notes for 3rd Sem BCA
164 pages
Overview of Operating Systems
PDF
91% (11)
Overview of Operating Systems
12 pages