
栈的实现
#!/usr/bin/env python
#coding=utf-8
#python version 2.7.4
class stack:
def __init__(self,list=None):
self.contain = list
self.msize=100;
self.top = 0;
def getTop(self):
if(self.top>0):
return self.contain[self.top-1]
else:
return None
def getLength(self):
return len(contain);
def push(self,str):
if(self.top==self.msize):
return -1
self.contain.append(str)
self.top=self.top +1
def pop(self):
try:
res=self.contain.pop()
return res;
except IndexError:
return None li = [1,'51','15']
st = stack(li)
va='5'
print st.pop()
print st.pop()
st.push('fdef')
print st.pop()
print st.pop()