#!/usr/bin/env python
class Stack(object):
"""docstring for Stack"""
def __init__(self):
self.__alist = []
def pop(self):
if not self.__alist:
print "your stack is empty"
else:
return self.__alist.pop()
def push(self,topush):
try:
self.__alist.append(topush)
except Exception,e:
print "error for %s" % e
def peek(self):
return self.__alist[len(self.__alist)-1]
def __del__(self):
del self
def showstack(self):
if not self.__alist:
print "your stack is empty"
else:
for e in reversed(self.__alist):
print e
print
def main():
astack = Stack()
choice = ""
while choice != "q":
print "P(u)sh"
print "P(p)op"
print "Pee(e)k"
print "S(s)how"
print "Q(q)uit"
choice = raw_input("make a choice:")
if choice == "u":
topush = raw_input("select an object to push:")
astack.push(topush)
elif choice == "p":
astack.pop()
elif choice == "e":
astack.peek()
elif choice == "s":
astack.showstack()
else:
print "choice is error!"
main()
class Stack(object):
"""docstring for Stack"""
def __init__(self):
self.__alist = []
def pop(self):
if not self.__alist:
print "your stack is empty"
else:
return self.__alist.pop()
def push(self,topush):
try:
self.__alist.append(topush)
except Exception,e:
print "error for %s" % e
def peek(self):
return self.__alist[len(self.__alist)-1]
def __del__(self):
del self
def showstack(self):
if not self.__alist:
print "your stack is empty"
else:
for e in reversed(self.__alist):
print e
def main():
astack = Stack()
choice = ""
while choice != "q":
print "P(u)sh"
print "P(p)op"
print "Pee(e)k"
print "S(s)how"
print "Q(q)uit"
choice = raw_input("make a choice:")
if choice == "u":
topush = raw_input("select an object to push:")
astack.push(topush)
elif choice == "p":
astack.pop()
elif choice == "e":
astack.peek()
elif choice == "s":
astack.showstack()
else:
print "choice is error!"
main()