队列和栈
来源:互联网 发布:淘宝网全球购是正品吗 编辑:程序博客网 时间:2024/06/05 23:55
队列
#!/usr/bin/env python#coding:utf-8"""file:class队列.pydate:2017-09-12 20:11author:lihangdesc:"""class Queue(object): def __init__(self): print "queue is creating..." self.queue = [] def EnQueue(self,item): self.queue.append(item) def ManyEnQueue(self,*args): self.queue.extend(args) def OutQueue(self): if not self.queue == []: return self.queue.pop(0) else: return None def show(self): for i in self.queue: print i def head(self): if not self.queue == []: return self.queue[0] else: return None def tail(self): if not self.queue == []: return self.queue[-1] else: return None def length(self): return len(self.queue) def isEmpty(self): return self.queue == [] def __del__(self): print "queue is deleting..."p1 = Queue()print p1.isEmpty()p1.EnQueue(1)p1.show()printp1.ManyEnQueue(2,3,4)p1.show()p1.OutQueue()printp1.show()printprint p1.isEmpty()
westos模块(栈中调用)
#!/usr/bin/env python#coding:utf-8"""file:westos.pydate:2017-09-12 21:30author:lihangdesc:"""class stack(object): def __init__(self,stack): self.stack = stack def push(self,item): self.stack.append(item) def manyPush(self,*args): self.stack.extend(args) def pop(self): if not self.isEmpty(): return self.stack.pop(-1) else: return None
栈
#!/usr/bin/env python#coding:utf-8"""file:class栈.pydate:2017-09-12 20:12author:lihangdesc:"""# import westosclass Stack(object): def __init__(self): print "stack is creating..." self.stack = [] def push(self,item): self.stack.append(item) def manyPush(self,*args): self.stack.extend(args) def outstack(self): if not self.stack == []: return self.stack.pop(0) else: return None def show(self): for i in self.stack: print i def top(self): if not self.stack == []: return self.stack[-1] else: return None def length(self): return len(self.stack) def isEmpty(self): return self.stack == [] def __del__(self): print "queue is deleting..."s1 = Stack()print s1.isEmpty()s1.push(1)s1.show()prints1.manyPush(2,3,4)s1.show()s1.outstack()prints1.show()printprint s1.isEmpty()
阅读全文
0 0
- 栈和队列--队列
- 【栈和队列】队列
- 栈、队列和优先队列
- 栈和队列(队列)
- 栈和队列--栈
- 【栈和队列】栈
- 栈和队列
- 栈和队列
- 表、栈和队列
- 栈和队列
- 栈和队列应用
- 栈和队列
- 栈和队列
- 栈和队列
- 栈和队列
- 栈和队列
- 队列和栈
- 栈和队列 小结
- 腾讯云服务端对接流程(独立模式)
- 类与对象
- Path使用--二阶贝塞尔曲线实现水波效果
- mysql引擎、索引、事务、锁、sql注入及java操作
- 最全Pycharm教程(12)——Pycharm调试器之Java脚本调试
- 队列和栈
- Oracle 11g Data Guard搭建物理Standby数据库(二)
- 第一个springmvc应用程序_注解版
- 梯度下降求解逻辑回归(Python)
- C#中using详解
- 使用回归树对美国波士顿房价训练数据进行学习,并对测试数据进行预测
- C#实现整数划分问题——带输出
- 多态
- 数据结构的学习 前言