forked from Vatsalparsaniya/Data-Structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
24 lines (19 loc) · 614 Bytes
/
Copy pathstack.py
File metadata and controls
24 lines (19 loc) · 614 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
class Stack(object):
def __init__(self,size):
self.index = -1
self.stack = [None] * size
def push(self, value):
if self.index != len(self.stack) -1:
self.index = self.index + 1
self.stack[self.index] = value
def pop(self):
if not self.empty():
value = self.stack[self.index]
self.stack[self.index] = None
self.index = self.index - 1
return value
def peek(self):
if not self.empty():
return self.stack[self.index]
def empty(self):
return self.index == -1