STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION &...
Transcript of STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION &...
![Page 1: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/1.jpg)
DATA STRUCTURES AND ALGORITHMS
IMRAN IHSANASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABADWWW.IMRANIHSAN.COM
LECTURES ADAPTED FROM:DANIEL KANE, NEIL RHODESDEPARTMENT OF CS & ENGINEERINGUNIVERSITY OF CALIFORNIA, SAN DIEGO
08STACKSIMPLEMENTATION & APPLICATIONS
![Page 2: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/2.jpg)
STACK
2
ABSTRACT DATA TYPE
• An Abstract Stack (Stack ADT) is an abstract data type which emphasizes specific operations:• Uses a explicit linear ordering• Insertions and removals are performed individually• Inserted objects are pushed onto the stack• The top of the stack is the most recently object pushed onto the stack• When an object is popped from the stack, the current top is erased
• Also called a last-in–first-out (LIFO) behavior• Graphically, we may view these operations as follows:
• There are two exceptions associated with abstract stacks:• It is an undefined operation to call either pop or top on an empty stack
![Page 3: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/3.jpg)
STACK
3
APPLICATIONS
• Numerous applications:• Parsing code:
• Matching parenthesis• XML (e.g., XHTML)
• Tracking function calls• Dealing with undo/redo operations• Reverse-Polish calculators• Assembly language
• The stack is a very simple data structure• Given any problem, if it is possible to use a stack,
this significantly simplifies the solution
• Problem solving:• Solving one problem may lead to subsequent problems• These problems may result in further problems• As problems are solved, your focus shifts back to the problem which lead to
the solved problem
• Notice that function calls behave similarly:• A function is a collection of code which solves a problem
![Page 4: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/4.jpg)
STACK
4
DEFINITION
• Abstract data type with the following operations:
Push(Key): adds key to collection
Key Top(): returns most recently-added key
Key Pop(): removes and returns most recently-added key
Boolean Empty(): are there any elements?
![Page 5: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/5.jpg)
BALANCED BRACKETS
5
• Input:
• A string str consisting of ‘(‘, ‘)’, ‘[‘,‘]’ characters.
• Output:
• Return whether or not the string’s parentheses and square brackets are balanced.
Balanced: Unbalanced:
“([])[]()”, “([]]()”
“((([([])]))())” “][”
![Page 6: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/6.jpg)
BALANCED BRACKETS
6
IsBalanced(str )
Stack stack
for char in str:
if char in [‘(‘, ‘[‘]:
stack.Push(char)
else:
if stack.Empty():
return False
top ← stack.Pop()
if (top = ‘[‘ and char != ‘]’) or
(top = ‘(‘ and char != ‘)’):
return False
return stack.Empty()
![Page 7: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/7.jpg)
STACK IMPLEMENTATION WITH ARRAY
7
numElements: 0
![Page 8: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/8.jpg)
STACK IMPLEMENTATION WITH ARRAY
8
numElements: 0
Push(a)
![Page 9: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/9.jpg)
STACK IMPLEMENTATION WITH ARRAY
9
numElements: 1
Push(a)
a
![Page 10: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/10.jpg)
STACK IMPLEMENTATION WITH ARRAY
10
numElements: 2
Push(b)
a b
![Page 11: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/11.jpg)
STACK IMPLEMENTATION WITH ARRAY
11
numElements: 2
Top() b
a B
![Page 12: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/12.jpg)
STACK IMPLEMENTATION WITH ARRAY
12
numElements: 3
Push(c)
a b c
![Page 13: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/13.jpg)
STACK IMPLEMENTATION WITH ARRAY
13
numElements: 2
Pop() c
a b
![Page 14: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/14.jpg)
STACK IMPLEMENTATION WITH ARRAY
14
numElements: 3
Push(d)
a b d
![Page 15: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/15.jpg)
STACK IMPLEMENTATION WITH ARRAY
15
numElements: 4
Push(e)
a b d e
![Page 16: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/16.jpg)
STACK IMPLEMENTATION WITH ARRAY
16
numElements: 5
Push(f)
a b d e f
![Page 17: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/17.jpg)
STACK IMPLEMENTATION WITH ARRAY
17
numElements: 5
Push(g) ERROR
a b d e f
![Page 18: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/18.jpg)
STACK IMPLEMENTATION WITH ARRAY
18
numElements: 5
Empty() False
a b d e f
![Page 19: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/19.jpg)
STACK IMPLEMENTATION WITH ARRAY
19
numElements: 4
Pop() f
a b d e
![Page 20: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/20.jpg)
STACK IMPLEMENTATION WITH ARRAY
20
numElements: 3
Pop() e
a b d
![Page 21: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/21.jpg)
STACK IMPLEMENTATION WITH ARRAY
21
numElements: 2
Pop() d
a b
![Page 22: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/22.jpg)
STACK IMPLEMENTATION WITH ARRAY
22
numElements: 1
Pop() b
a
![Page 23: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/23.jpg)
STACK IMPLEMENTATION WITH ARRAY
23
numElements: 0
Pop() a
![Page 24: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/24.jpg)
STACK IMPLEMENTATION WITH ARRAY
24
numElements: 0
Empty() True
![Page 25: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/25.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
25
Empty Linked List/
head
![Page 26: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/26.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
26
Push(a)
a
/
head
![Page 27: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/27.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
27
Push(b)
a
/
head
b
![Page 28: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/28.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
28
Top() b
a
/
head
b
![Page 29: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/29.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
29
Push(c)
a
/
head
bc
![Page 30: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/30.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
30
Pop() c
a
/
head
b
![Page 31: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/31.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
31
Push(d)
a
/
head
bd
![Page 32: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/32.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
32
Push(e)
a
/
head
bde
![Page 33: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/33.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
33
Push(f)
a
/
head
bdef
![Page 34: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/34.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
34
Empty() False
a
/
head
bdef
![Page 35: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/35.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
35
Pop() f
a
/
head
bde
![Page 36: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/36.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
36
Pop() e
a
/
head
bd
![Page 37: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/37.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
37
Pop() d
a
/
head
b
![Page 38: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/38.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
38
Pop() b
a
/
head
![Page 39: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/39.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
39
Pop() a
/
head
![Page 40: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/40.jpg)
STACK IMPLEMENTATION WITH LINKED LIST
40
Empty() True
/
head
![Page 41: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/41.jpg)
PARSING XHTML
41
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 42: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/42.jpg)
PARSING XHTML
42
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 43: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/43.jpg)
PARSING XHTML
43
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 44: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/44.jpg)
PARSING XHTML
44
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 45: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/45.jpg)
PARSING XHTML
45
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 46: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/46.jpg)
PARSING XHTML
46
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 47: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/47.jpg)
PARSING XHTML
47
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 48: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/48.jpg)
PARSING XHTML
48
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 49: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/49.jpg)
PARSING XHTML
49
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 50: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/50.jpg)
PARSING XHTML
50
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 51: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/51.jpg)
PARSING XHTML
51
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 52: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/52.jpg)
PARSING XHTML
52
STACK APPLICATIONS
<html>
<head><title>Hello</title></head>
<body><p>This appears in the <i>browser</i>.</p></body>
</html>
![Page 53: STACKS - imranihsan.comimranihsan.com/upload/lecture/DSAF1708.pdf · 08 STACKS IMPLEMENTATION & APPLICATIONS. STACK 2 ABSTRACT DATA TYPE • An Abstract Stack (Stack ADT) is an abstract](https://reader035.fdocuments.us/reader035/viewer/2022062605/5fd715b019ed86198c0e10f7/html5/thumbnails/53.jpg)
SUMMARY
53
• Stacks can be implemented with either an array or a linked list.
• Each stack operation is O(1):
• Push, Pop, Top, Empty.
• Stacks are occasionally known as LIFO queues.