网站大量收购独家精品文档,联系QQ:2885784924

栈栈的应用队列优先队列8.ppt

  1. 1、本文档共101页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
栈栈的应用队列优先队列8

栈 栈的应用 队列 优先队列 栈 ( Stack ) 栈和队列 都是特殊的线性表 限定性的线性表 操作受限的线性表 一、栈 限定只在表的一端访问的线性表 元素只能从栈顶插入和删除 先进后出 后进先出 例 羊肉串 子弹夹 货 栈 顺序栈——栈类的顺序表示 #ifndef STACK_CLASS #define STACK_CLASS #include iostream.h #include stdlib.h const int MaxStackSize = 50; templateclass T class Stack { T stacklist[MaxStackSize]; int top; public: Stack (void); void Push (const T item); T Pop (void); void ClearStack(void); T Peek (void) const; //gettop int StackEmpty(void) const; int StackFull(void) const; }; // initialize stack top. templateclass T StackT::Stack (void) : top(-1) { } // push item on the the stack templateclass T void StackT::Push (const T item) { // if stacklist is full, terminate the program if (top == MaxStackSize-1) { cerr Stack overflow! endl; exit(1); } // increment top and copy item to stacklist top++; stacklist[top] = item; } // pop the stack and return the top element templateclass T T StackT::Pop (void) { T temp; // if stack is empty, terminate the program if (top == -1) {cerr Attempt to pop an empty stack! endl; exit(1); } temp = stacklist[top]; // record the top element top--; return temp; } // return the value at the top of the stack templateclass T T StackT::Peek (void) const { // if the stack is empty, terminate the program if (top == -1) {cerr Attempt to peek at an empty stack! endl; exit(1); } return stacklist[top]; } // test for an empty stack templateclassT int StackT::StackEmpty(void) const { // return the logical value top == - 1 return top == -1; } // test for a full stack templateclass T int StackT::StackFull(void) const { // test the position of top return top == MaxStackSize-1; } // clear all items from the stack templateclass T void StackT::ClearStack(void) { top = -1; } #endif // ST

文档评论(0)

jixujianchi + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档