第3章专题1栈的课件内容.pptVIP

  • 3
  • 0
  • 约6.95千字
  • 约 53页
  • 2019-04-20 发布于山东
  • 举报
template class DataType void LinkStackDataType ::Push(DataType x) { s = new NodeDataType; s-data = x; s-next = top; top = s; } top an an-1 a1 ∧ 链栈的实现——插入 x s top 操作接口: void Push(DataType x); 为什么没有判断栈满? 3.1 栈 template class DataType DataType LinkStackDataType ::Pop( ) { if (top == NULL) throw 下溢; x = top-data; p = top; top = top-next; delete p; return x; } 链栈的实现——插入 操作接口: DataType Pop( ); top an an-1 a1 ∧ top p top++可以吗? 3.1 栈 顺序栈和链栈的比较 时间性能:相同,都是常数时间O(1)。 空间性能: 顺序栈:有元素个数的限制和空间浪费的问题。 链栈:没有栈满的问题,只有当内存没有可用空间时才会出现栈满,但是每个元素都需要一个指针域,从而产

文档评论(0)

1亿VIP精品文档

相关文档