Skip to content

Instantly share code, notes, and snippets.

@abhiksark
Created October 12, 2016 16:49
Show Gist options
  • Save abhiksark/1b0a9bdf3cdc0811b53b8c3dd9cc0497 to your computer and use it in GitHub Desktop.
Save abhiksark/1b0a9bdf3cdc0811b53b8c3dd9cc0497 to your computer and use it in GitHub Desktop.
Stack/Python
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 10 10:33:04 2016
@author: abhik
Stack Implementation
"""
class Stack(object):
def __init__(self,limit=10):
self.stk=[]
self.limit=limit
def isEmpty(self):
return len (self.stk)<=0
def push(self,item):
if len(self.stk) >=self.limit:
print "Stack OverFlow"
else :
self.stk.append(item)
print "Stack after Push",self.stk
def pop(self):
if len(self.stk)<=0:
print "Stack UnderFlow"
else:
return self.stk.pop()
def peek(self):
if len(self.stk)<=0:
print "Stack UnderFlow"
return 0
else:
return self.stk[-1]
def size(self):
return len(self.stk)
if __name__=="__main__":
stack=Stack()
stack.push(21)
stack.pop()
print stack.peek()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment