Python 实现栈
2016-06-01 23:15
337 查看
#coding=utf-8
class Stack():
def __init__(st,size):
st.stack=[];
st.size=size;
st.top=-1;
def push(st,content):
if st.Full():
print "Stack is full!"
else:
st.stack.append(content)
st.top=st.top+1
def Full(st):
if st.top==st.size:
return True
else:
return False
def Empty(st):
if st.top==-1:
print "Stack if Empty!"
def pop(st):
if st.Empty():
print "Stack is Empty!"
else:
st.stack.pop(content)
st.top=st.top-1
Q=Stack(7)
print Q.Empty()
Q.push("hello")
Q.push(5)
Q.push(4)
Q.push(3)
Q.push(2)
Q.push(1)
#print Q.Empty()
Python实现 栈操作
class Stack():
def __init__(st,size):
st.stack=[];
st.size=size;
st.top=-1;
def push(st,content):
if st.Full():
print "Stack is full!"
else:
st.stack.append(content)
st.top=st.top+1
def Full(st):
if st.top==st.size:
return True
else:
return False
def Empty(st):
if st.top==-1:
print "Stack if Empty!"
def pop(st):
if st.Empty():
print "Stack is Empty!"
else:
st.stack.pop(content)
st.top=st.top-1
Q=Stack(7)
print Q.Empty()
Q.push("hello")
Q.push(5)
Q.push(4)
Q.push(3)
Q.push(2)
Q.push(1)
#print Q.Empty()
Python实现 栈操作
相关文章推荐
- Python菜鸟之路:Python基础-内置函数补充
- Python学习 (系列练习1)
- python 学习笔记8 函数式编程functional programming
- eclipse中搭建python开发环境(windows环境)
- numpy基础操作
- Bluemix上Python应用启动ERR import MySQLdb ImportError: No module named MySQLdb
- Eclat算法Python实现
- 两款Python工具推荐
- LeetCode Compare Version Numbers
- Python--python爬虫神器PyQuery
- Python中实现通用代理对象
- Python--python基础知识(3)
- Windows7 64位+python3.4环境下安装opencv3.0的方法
- python 语句5
- python语句(4)
- python 文件2学习
- python 文件1
- virtualenv 指定 python 解释器的版本
- Python学习之基础总结--3
- python的内建函数(BIF)range(start, stop, step)