用dart 语言实现一个简单的stack(栈).栈的内部用List实现. class Stack<E> { final List<E> _stack; final int capacity; int _top; Stack(this.capacity) : _top = -1, _stack = List<E>(capacity); bool get isEmpty => _top == -1; bool get isFull => _top == capa…
计算器的bin/calc.dart 可执行代码: import 'dart:io'; import 'package:data_struct/stack/sample/calculator.dart'; void main() { print('please input the expression:'); var ins = stdin.readLineSync(); while (ins != 'exit') { try { var r = calc(ins); print('\n the…
之前发过一篇stack的实现,是采用dart内置的List类并固定长度数组实现的.这里重新实现一版,重复利用List类内置特性和方法.实现更为简洁. class Stack<E> { final List<E> _stack; Stack() : _stack = <E>[]; bool get isEmpty => _stack.isEmpty; bool get isNotEmpty => _stack.isNotEmpty; int get size…