Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack...
Transcript of Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack...
![Page 1: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/1.jpg)
Stack Implementation
Mr. Mubashir AliLecturer (Dept. of Software Engineering)
[email protected] Garrison University, Lahore
1
Lecture 12
![Page 2: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/2.jpg)
Previous Lecture
1. Stack
2. Stack Operations
3. Stack Applications
Mubashir Ali - Lecturer (Department of Software Engineering)
2
![Page 3: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/3.jpg)
Outline
1. Array Based Implementation
2. Linked List Based Implementation
3. Stack Member Functions in STL
Mubashir Ali - Lecturer (Department of Software Engineering)
3
![Page 4: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/4.jpg)
Algorithm for PUSH Operation
• Check if the stack is full or not.
• If the stack is full, then print error of overflow andexit the program.
• If the stack is not full, then increment the top andadd the element.
Mubashir Ali - Lecturer (Department of Software Engineering)
4
![Page 5: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/5.jpg)
Algorithm for POP Operation
• Check if the stack is empty or not.
• If the stack is empty, then print error of underflowand exit the program.
• If the stack is not empty, then print the element atthe top and decrement the top.
Mubashir Ali - Lecturer (Department of Software Engineering)
5
![Page 6: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/6.jpg)
Array Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
6
![Page 7: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/7.jpg)
Array Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
7
![Page 8: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/8.jpg)
Array Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
8
![Page 9: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/9.jpg)
Array Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
9
![Page 10: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/10.jpg)
Linked List Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
10
![Page 11: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/11.jpg)
Linked List Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
11
![Page 12: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/12.jpg)
Linked List Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
12
![Page 13: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/13.jpg)
Linked List Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
13
![Page 14: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/14.jpg)
Stack Member Functions in STL
Mubashir Ali - Lecturer (Department of Software Engineering)
14
![Page 15: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/15.jpg)
Lab-6
Write C++ program to perform followingimplementation of Stack with all essentialoperations,
1. Array based implementation
2. Linked List based implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
15
![Page 16: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/16.jpg)
Summary
1. Array Based Implementation
2. Linked List Based Implementation
3. Stack Member Functions in STL
Mubashir Ali - Lecturer (Department of Software Engineering)
16
![Page 17: Lecture 12 Stack Implementation - Learn With …...Lecture 12 Previous Lecture 1. Stack 2. Stack Operations 3. Stack Applications Mubashir Ali - Lecturer (Department of Software Engineering)](https://reader036.fdocuments.us/reader036/viewer/2022070721/5ee3052ead6a402d666d2716/html5/thumbnails/17.jpg)
References
you will be able to find course resources at
http://www.mubashirali.com/data-structures-algorithms/
Topic 4.1 and 4.4 (Data Structures and Algorithms in C++ byAdam Drozdek)
Mubashir Ali - Lecturer (Department of Software Engineering)
17