class Node:#节点类
next = None#节点指针指向下一个
def __init__(self,data):
self.data=data
------------------------------------------
class Queue:
first = Node(None)#头节点
last = Node(None)#尾节点
def inQueue(self,node):#进队列
if self.first.data==None:
self.first = node
self.last = node
else:
self.last.next = node
self.last = node
def deQueue(self):#出队列
node = self.first
self.first = self.first.next
return node
q = Queue()#创建队列对象
q.inQueue(Node(1))#进队
q.inQueue(Node(2))#进队
n = q.deQueue()#出队
m = q.deQueue()#出队
print n.data,m.data
--------------------------------
class Stack:#栈
top = Node(None)
def add(self,node):#进栈
node.next=self.top
self.top = node
def out(self):#出栈
node =self.top
while node.data!=None:
print node.data,
node= node.next
s =Stack()
s.add(Node(1))#进栈
s.add(Node(2))#进栈
s.add(Node(3))#进栈
s.out()#出栈