Advertisement
Sunilsai

Stack_Implementation

May 22nd, 2022
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. class Stack:
  2.     def __init__(self, Size):
  3.         self.Stack = [None]*Size
  4.         self.Ind = -1
  5.        
  6.     def Push(self, Val):
  7.         self.Ind += 1
  8.         self.Stack[self.Ind] = Val
  9.    
  10.     def Pop(self):
  11.         self.Stack[self.Ind] = None
  12.         self.Ind -= 1
  13.    
  14.     def Peek(self):
  15.         return self.Stack[self.Ind]
  16.        
  17.     def isEmpty(self):
  18.         return self.Ind == -1
  19.        
  20. StackObj = Stack(5)
  21. StackObj.Push(10)
  22. StackObj.Push(12)
  23. StackObj.Push(16)
  24. print(StackObj.Peek())
  25. StackObj.Pop()
  26. print(StackObj.Peek())
  27. StackObj.isEmpty()
  28. print(StackObj.Stack)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement