MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / Stack

Class Stack

data_structures/stacks/__init__.py:1–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Stack:
2
3 def __init__(self):
4 self.stack = []
5 self.top = 0
6
7 def is_empty(self):
8 return (self.top == 0)
9
10 def push(self, item):
11 if self.top < len(self.stack):
12 self.stack[self.top] = item
13 else:
14 self.stack.append(item)
15
16 self.top += 1
17
18 def pop(self):
19 if self.is_empty():
20 return None
21 else:
22 self.top -= 1
23 return self.stack[self.top]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected