-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
57 lines (49 loc) · 907 Bytes
/
stack.py
File metadata and controls
57 lines (49 loc) · 907 Bytes
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
class Stack():
def __init__(self):
self.stack = []
def empty(self):
return self.stack == []
def clear(self):
del self.stack[:]
def show(self):
return self.stack[:]
def size(self):
return len(self.stack)
def push(self, item):
self.stack.append(item)
def pop(self):
return self.stack.pop()
def top(self):
return self.stack[self.size() -1]
s = Stack()
s.push(8)
s.push(9)
s.push(10)
s.push(11)
print s.show()
print s.size()
if not s.empty():
print 11
s.pop()
print s.show()
print s.size()
if not s.empty():
print 22
s.pop()
print s.show()
print s.size()
if not s.empty():
print 33
s.pop()
print s.show()
print s.size()
if not s.empty():
print 44
s.pop()
print s.show()
print s.size()
if not s.empty():
print 55
s.pop()
print s.show()
print s.size()