-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.html
85 lines (74 loc) · 1.5 KB
/
stack.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<html>
<head>
<script src="stack.js"></script>
<style>
body {
font-family: arial
}
h1 {
color: blue
}
</style>
</head>
<body>
<h1>Stack</h1>
<script>
var stackArray = [9, 100, 22, 5, 3, 3];
var stack = new Stack(stackArray);
function printStackAuxiliaryInfo(stack) {
document.write('<i>Size</i>: ' + stack.size());
document.write('<br/>');
document.write('<i>isEmpty</i>: ' + stack.isEmpty());
document.write('<br/>');
document.write('<br/>');
document.write(stack.toString());
}
</script>
<h3>Input List</h3>
<script>
document.write(stackArray.join(', '));
</script>
<h3>Convert to Stack</h3>
<script>
document.write('<i>Array</i>: ' + stack.toString());
document.write('<br/>');
printStackAuxiliaryInfo(stack);
</script>
<h3>Pop</h3>
<script>
document.write('<i>Popped</i>: ' + stack.pop());
document.write('<br/>');
printStackAuxiliaryInfo(stack);
</script>
<h3>Peek</h3>
<script>
document.write('<i>Peeked</i>: ' + stack.peek());
document.write('<br/>');
printStackAuxiliaryInfo(stack);
</script>
<h3>Insert (20)</h3>
<script>
stack.insert(20);
printStackAuxiliaryInfo(stack);
</script>
<h3>Pop Until 2 Items Left</h3>
<script>
while (stack.size() > 2) {
stack.pop();
}
printStackAuxiliaryInfo(stack);
</script>
<h3>Pop Until Empty</h3>
<script>
while (!stack.isEmpty()) {
stack.pop();
}
printStackAuxiliaryInfo(stack);
</script>
<h3>Pop from Empty Stack</h3>
<script>
stack.pop();
printStackAuxiliaryInfo(stack);
</script>
</body>
</html>