MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / Stack

Class Stack

Python/stack using linked list.py:16–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14 curNode=curNode.next
15
16class Stack:
17 def __init__(self):
18 self.LinkedList=LinkedList()
19
20 def __str__(self):
21 values=[str(x.value) for x in self.LinkedList]
22 return '\n'.join(values)
23
24 def isEmpty(self):
25 if self.LinkedList.head == None:
26 return True
27 else:
28 return False
29
30 def push(self,value):
31 node=Node(value)
32 node.next=self.LinkedList.head
33 self.LinkedList.head = node
34
35 #pop
36 def pop(self):
37 if self.isEmpty():
38 print("there is no element in the stack")
39 else:
40 nodeValue=self.LinkedList.head.value
41 self.LinkedList.head=self.LinkedList.head.next
42 return nodeValue
43
44 # peek
45 def peek(self):
46 if self.isEmpty():
47 print("there is no element in the stack")
48 else:
49 nodeValue=self.LinkedList.head.value
50 return nodeValue
51
52
53
54 # delete entire stack
55 def delete(self):
56 self.list=None
57
58
59customStack = Stack()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected