[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 ...
随机推荐
- 牛客网 PAT 算法历年真题 1011 : 个位数统计 (15)
个位数统计 (15) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 给定一个k位整数N = dk-1*10k- ...
- 加号变空格问题 url参数 post get 请求发送
问题:加号后台接收变空格问题 结论: 1.任何get拼接的请求 参数key value 需要编码后在拼接 2.get请求避免做数据提交,用post提交.jq,axios的post提交默认编码了不会有问 ...
- 【性能测试工具ab】ab工具使用
1.在安装了apache服务器后,或者wampserver后,在bin目录下,有一个ab.exe文件 2.使用,进入ab.exe所在的文件夹 3.ab -c 10 -n 1000 htt ...
- xshell提示必须安装最新的更新
今天大家的xshell基本都出了这个问题 调整时间,调整到比较前的时间,打开xshell即可. 然后工具->选项 把更新去了
- git-github-TortoiseGit综合使用教程(二)快速入门
:建立版本库 在github网站上创建一个版本库,并复制clone地址. git@github.com:jackadam1981/Flask_Base.git https://github.com/j ...
- asp.net MVC之Action过滤器浅析
在asp.net MVC中,Action过滤器是一大利器,它可以在以下两个步骤执行相关的代码: 1.执行Action方法之前:OnActionExecuting 2.Action方法执行完毕后:OnA ...
- win10企业版激活
slmgr.vbs /upk slmgr /ipk NPPR9-FWDCX-D2C8J-H872K-2YT43 slmgr /skms zh.us.to slmgr /ato
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法
1.导入mysql-connector-java-5.1.26-bin.jar包,我试着把maven中自动下载下来的mysql-connector-java-5.1.26.jar包导入,还是没能解决问 ...
- C++类构造函数初始化列表(转)
构造函数初始化列表以一个冒号开始,接着是以逗号分隔的数据成员列表,每个数据成员后面跟一个放在括号中的初始化式.例如: { public: int a; float b; //构 ...
- Linux文件系统命令 cat
命令名:cat 功能:在当前窗口中查看制定位置的文件的内容. eg: renjg@renjg-HP-Compaq-Pro--MT:~/test$ cat /etc/apache2/ports.conf ...