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的更多相关文章

  1. uva 11995 I Can Guess the Data Structure stack,queue,priority_queue

    题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...

  2. Data Structure Stack: Reverse a stack using recursion

    http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/ #include <iostream> #include < ...

  3. Data Structure Stack: Infix to Postfix

    http://geeksquiz.com/stack-set-2-infix-to-postfix/ #include <iostream> #include <vector> ...

  4. Python: tree data structure

    # 树结构 from pythonds.basic.stack import Stack #pip install pythonds from pythonds.trees.binaryTree im ...

  5. 笔记-python-tutorial-5.data structure

    笔记-python-tutorial-5.data structure 1.      data structure 1.1.    list operation list.append(x) #尾部 ...

  6. HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...

  7. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  8. 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 ...

  9. HDU 5929 Basic Data Structure 模拟

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

随机推荐

  1. 套接字编程,创建套接字socket

    1.套接字地址结构: struct sockaddr { sa_family_t sa_family; char sa_data[14]; }; 其中,成员sa_family表示套接字的协议族类型,对 ...

  2. 4.4基于switch语句的译码器

    Q:已知前缀码如右图所示,求0/1字符串“001011101001011001”相对应的译码. a b c 1 01 001 #include<iostream> #include< ...

  3. POJ 2002 Squares 几何, 水题 难度: 0

    题目 http://poj.org/problem?id=2002 题意 已知平面内有1000个点,所有点的坐标量级小于20000,求这些点能组成多少个不同的正方形. 思路 如图,将坐标按照升序排列后 ...

  4. xpath & <tr><td><br>

    python : 3.6 lxml : 4.2.1 from lxml.html import etree test_html = ''' <!DOCTYPE html PUBLIC " ...

  5. PC/FORTH定点原理

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...

  6. 《Python》网络编程之客户端/服务端框架、套接字(socket)初使用

    一.软件开发的机构 我们了解的涉及到两个程序之间通讯的应用大致可以分为两种: 第一种是应用类:QQ.微信.网盘等这一类是属于需要安装的桌面应用 第二种是web类:比如百度.知乎.博客园等使用浏览器访问 ...

  7. VCL界面控件DevExpress VCL Controls发布v18.2.5|附下载

    DevExpress VCL Controls是 Devexpress公司旗下最老牌的用户界面套包.所包含的控件有:数据录入,图表,数据分析,导航,布局,网格,日程管理,样式,打印和工作流等,让您快速 ...

  8. AbstractBootstrap.bind()

    ------------------headContext也就是pipeline最开头的那个handlercontext中的bind方法@Override public void bind( Chan ...

  9. 20165326 java第三周学习笔记

    纸质学习笔记 代码托管

  10. 客户端优化之使用javascript原生方法替代复杂的数学运算和jquery方法

    尽管jQuery等js框架相比原生javascript使用起来极为方便但是为什么在一些大型互联网公司还是一致强调前端开发人员的js基础,因为尽管javascript使用起来可能非常不便不仅体现在语法而 ...