forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackClass.py
More file actions
40 lines (28 loc) · 835 Bytes
/
StackClass.py
File metadata and controls
40 lines (28 loc) · 835 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
class Stack():
def __init__(self):
self.stack = list()
def push(self, item):
self.stack.append(item)
def pop(self):
if len(self.stack) > 0:
return self.stack.pop()
def peek(self):
if len(self.stack) > 0:
return self.stack[len(self.stack)-1]
else:
return None
def __str__(self):
return str(self.stack)
# class Stack():
# def __init__(self):
# self.stack = list()
# def push(self, item):
# self.items.append(item)
# def pop(self):
# return self.items.pop()
# def peek(self):
# return self.items[len(self.items)-1]
# def size(self):
# return len(self.items)
# def is_empty(self):
# return self.items == []