[Data Structure] An Algorithm for Matching Delimiters
An important task when processing arithmetic expressions is to mach delimiters.
We can use Stack to solve this problem.
def is_matched(expr):
left='({['
right=')}]' S=ArrayStack() for c in expr:
if c in left:
S.push(c)
elif c in right:
if S.is_empty():
return False
if right.index(c)!=left.index(S.pop()):
return False
return S.is_empty()
[Data Structure] An Algorithm for Matching Delimiters的更多相关文章
- <Data Structure and Algorithm>排序算法
排序稳定:如果两个数相同,对他们进行的排序结果为他们的相对顺序不变.例如A={1,2,1,2,1}这里排序之后是A = {1,1,1,2,2} 稳定就是排序后第一个1就是排序前的第一个1,第二个1就是 ...
- [Algorithm] Heap data structure and heap sort algorithm
Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...
- [Algorithm] Trie data structure
For example we have an array of words: [car, done, try, cat, trie, do] What is the best data structu ...
- [Algorithm] JavaScript Graph Data Structure
A graph is a data structure comprised of a set of nodes, also known as vertices, and a set of edges. ...
- [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- 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 ...
- CDOJ 483 Data Structure Problem DFS
Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...
- HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
随机推荐
- Microsoft Windows远程桌面协议中间人攻击漏洞(CVE-2005-1794)漏洞解决方案(Windows server2003)
1.启动“终端服务配置” 2.选择“连接”,看到“RDP-Tcp”,在其上右键,选择“属性” 3.“常规”选项卡,将加密级别修改为“符合FIPS标准”,点击应用 应用即可,实验发现并不需要重启服务或操 ...
- Windows与Linux的回车换行转换
最初"\r"(return)表示“回车”即回到行首,“\n”(next)表示“换行”即定位到下一行:UNIX和Linux使用“\n”换行,而Windows用“\r\n”(不是\n\ ...
- 关于TCP长连接和发送心跳的一些理解
原因 TCP是一种有连接的协议,但是这个连接并不是指有一条实际的电路,而是一种虚拟的电路.TCP的建立连接和断开连接都是通过发送数据实现的,也就是我们常说的三次握手.四次挥手.TCP两端保存了一种数据 ...
- 转 Visual C++6.0 与matlab联合编程(2)----Visual C++6.0 环境下编译和调试MEX文件
我的最初想法是利用matlab的mex命令调用C++程序生成动态链接库的,但是测试程序(文中另附)通过了,自己的实际应用程序却没有过.还是把方法贴在这儿,以便自己以后进行整理. http://shij ...
- EtherCAT(扒自百度百科)
EtherCAT(以太网控制自动化技术)是一个开放架构,以以太网为基础的现场总线系统,其名称的CAT为控制自动化技术(Control Automation Technology)字首的缩写.Ether ...
- java 数据溢出和编译错误的差别
int a=100000000000;编译错误,超出int范围 int a=2100000000; int b=a*12020200;数据溢出,a并未溢出,但b在通过a计算后的数据溢出 long e= ...
- go语言byte类型报错cannot use "c" (type string) as type byte in assignment
练习Go修改字符串的时候遇到这个问题:cannot use "c" (type string) as type byte in assignment,代码如下: package m ...
- compile openjdk7 in ubuntu OS
success: openjdk version "1.7.0-internal"OpenJDK Runtime Environment (build 1.7.0-internal ...
- day15 装饰器
关于函数的装饰器 1 .装饰器,(难点,重点) 开闭原则: 对功能的扩展开放 对代码的修改是封闭 通用装饰器语法: def wrapper(fn): def inner(*args,**kwargs) ...
- HTML语义化简介思维导图