View
6
Download
1
Category
Preview:
Citation preview
Stack Implementation
Mr. Mubashir AliLecturer (Dept. of Software Engineering)
mubashirali@lgu.edu.pkLahore Garrison University, Lahore
1
Lecture 12
Previous Lecture
1. Stack
2. Stack Operations
3. Stack Applications
Mubashir Ali - Lecturer (Department of Software Engineering)
2
Outline
1. Array Based Implementation
2. Linked List Based Implementation
3. Stack Member Functions in STL
Mubashir Ali - Lecturer (Department of Software Engineering)
3
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
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
Array Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
6
Array Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
7
Array Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
8
Array Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
9
Linked List Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
10
Linked List Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
11
Linked List Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
12
Linked List Based Implementation
Mubashir Ali - Lecturer (Department of Software Engineering)
13
Stack Member Functions in STL
Mubashir Ali - Lecturer (Department of Software Engineering)
14
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
Summary
1. Array Based Implementation
2. Linked List Based Implementation
3. Stack Member Functions in STL
Mubashir Ali - Lecturer (Department of Software Engineering)
16
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
Recommended