Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- def __init__(self):
- self.data = None
- self.nextNode = None
- class LLStack:
- def __init__(self):
- self.head = None
- self.tail = None
- def Push(self, value):
- current = Node()
- current.data = value
- if self.head == None:
- current.nextNode = None
- self.head = current
- else:
- current.nextNode = self.head
- self.head = current
- def Pop(self):
- if self.head == None:
- print("Stack Underflow")
- elif self.head.nextNode == None:
- self.head = None
- else:
- self.head = self.head.nextNode
- def viewStack(self):
- outString = ""
- if not(self.head == None):
- current = self.head
- while not(current == None):
- outString = outString + str(current.data) + ", "
- current = current.nextNode
- print(outString)
- else:
- print("Nothing in stack")
- stack = LLStack()
- stack.viewStack()
- stack.Pop()
- stack.viewStack()
- stack.Push(5)
- stack.viewStack()
- stack.Push(10)
- stack.viewStack()
- stack.Pop()
- stack.viewStack()
- stack.Pop()
- stack.viewStack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement