您的位置:首页 > 理论基础 > 数据结构算法

栈和队列在python中的数据结构

2017-05-31 11:47 197 查看
栈的数据结构
# coding=utf-8class 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+1def Full(st):if st.top==st.size:return Trueelse:return Falsedef Empty(st):if st.top==-1:return  Trueelse:return  Falsedef Out(st):if st.Empty():print"The stack is empty!"else:st.top=st.top-1
队列的数据结构
class Queue():def __init__(qu,size):qu.Queue=[];qu.size=size;qu.head=-1;qu.tail=-1;def Empty(qu):if qu.head==qu.tail:return Trueelse:Falsedef Full(qu):if qu.tail-qu.head+1==qu.size:return Trueelse:return Falsedef enQueue(qu,content):if qu.Full():print "the Queue is Full!"else:qu.Queue.append(content)qu.tail=qu.tail+1def outQueue(qu):if qu.Empty():print "the Queue is empty!"else:qu.head=qu.head+1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据结构 python