[Data Structure] Stack Implementation in Python
We can realize a Stack as an adaptation of a Python List.
S.push(e)=L.append(e)
S.pop()=L.pop()
S.top()=L[-1]
S.len()=len(L)
S.is_empty=(len(L)==0)
class Empty(Exception):
pass class ArrayStack:
"""LIFO Stack implementation using Python""" def __init__(self):
self._data=[] def __len__(self):
return len(self._data) def is_empty(self):
return len(self._data)==0 def push(self,e):
self._data.append(e) def pop(self):
if self.is_empty():
raise Empty('Stack is empty')
return self._data.pop() def top(self):
if self.is_empty():
raise Empty('Stack is empty')
return self._data[-1]
[Data Structure] Stack Implementation in Python的更多相关文章
- uva 11995 I Can Guess the Data Structure stack,queue,priority_queue
题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...
- Data Structure Stack: Reverse a stack using recursion
http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/ #include <iostream> #include < ...
- Data Structure Stack: Infix to Postfix
http://geeksquiz.com/stack-set-2-infix-to-postfix/ #include <iostream> #include <vector> ...
- Python: tree data structure
# 树结构 from pythonds.basic.stack import Stack #pip install pythonds from pythonds.trees.binaryTree im ...
- 笔记-python-tutorial-5.data structure
笔记-python-tutorial-5.data structure 1. data structure 1.1. list operation list.append(x) #尾部 ...
- HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...
- hdu-5929 Basic Data Structure(双端队列+模拟)
题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- UVa 11995:I Can Guess the Data Structure!(数据结构练习)
I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...
- HDU 5929 Basic Data Structure 模拟
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
随机推荐
- linux查看主机最后启动时间
1.使用who查看最后重启时间 who -b 2.使用last查看近几次重启时间 last reboot 第一条即为最后一次重启日期 last其实是查询用户的登录记录,reboot是一个伪用户:也就是 ...
- Latex常用数学符号(转)
http://blog.sina.com.cn/s/blog_642075770100u0np.html Latex常用数学符号(转) 1.指数和下标可以用^和_后加相应字符来实现.比如: 2.平方根 ...
- for-each、for-in和for-of的区别
for-each.for-in和for-of的区别 1.forEach()方法 用于调用数组的每个元素,并将元素传递给回调函数. 注意: forEach() 对于空数组是不会执行回调函数的. arra ...
- Oracle Rman 控制RMAN的备份时间,减少IO消耗
一.问题描述 由于服务器配置不高,备份策略为周末全备.周一至周六差异备份. 平时服务器CPU使用30%左右. 全备份时,开启两个通道,CPU达到70%-80%左右,业务不卡顿.不掉单,session不 ...
- C++构造函数和析构函数,以及构造函数特殊成员变量和函数的初始化
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- angular4-常用指令
ngIf 指令(它与 AngularJS 1.x 中的 ng-if 指令的功能是等价) <div *ngIf="condition">...</div> n ...
- 软件设计基础-C/S系统
在软件设计开发过程中,逐渐形成了一些针对特定应用领域的软件系统组织方式的惯用模式 如经典的C/S(client/server,客户/服务器)模式和B/S(browser/server,浏览器/服务器) ...
- Java 将图片转成base64,传到前台展示
后台代码: public String getBase64(SysFile sysFile){ String imgStr = ""; try { File file = new ...
- FPGA的GTP(aurora 协议)高速串行接口数据收发(转)
reference:https://blog.csdn.net/qq_40261818/article/details/83039829 PG046-Aurora 8B/10B Logicore I ...
- Android开发 ---Activity的7种运行状态
Android开发 ---Activity的7种运行状态 创建 --> 启动 --> 运行 --> 暂停 --> 停止 --> 销毁 重启 操作图解: 1.MainA ...