《数据结构的算法在C++中的应用》(英文版)Chapter 5 Stack

Chapter 5 Stack
Chapter 5 Stack

5.1 definition of stack Definition a stack is a linear list in which insertions and deletions take place at the same end.This end is called the top. The other end of the list is called the bottom It is also called a lifo(last-in-first-out)list
5.1 definition of stack Definition : A stack is a linear list in which insertions and deletions take place at the same end.This end is called the top. The other end of the list is called the bottom. It is also called a LIFO(last-in-first-out) list

5.1 definition of stack Figure 5. 1 stack configurations E长top DK-top DCB B Btop A长 bottomA< bottom A长 bottom
5.1 definition of stack Figure 5.1 stack configurations Etop Dtop D C C B B Btop Abottom Abottom Abottom

5.2 ADT Stack AbstractData Type Stacki instances linear list of elements one end is called the bottom the other is the top operations Create: Create an empty stack; IsEmpty O: Return true if stack is empty, return false otherwise
5.2 ADT stack AbstractDataType Stack{ instances linear list of elements;one end is called the bottom;the other is the top; operations Create():Create an empty stack; IsEmpty():Return true if stack is empty,return false otherwise

5.2 ADT Stack IsFull o: Return true if stack if full, return false otherwise Top(: return top element of the stack; Add(x) add element x to the stack Delete(): Delete top element from stack and put it In X
5.2 ADT stack IsFull ():Return true if stack if full,return false otherwise; Top():return top element of the stack; Add(x): add element x to the stack; Delete(x):Delete top element from stack and put it in x; }

5.3 Formula-based representation We may use the Formula-based representation 012 top maxtop-l stack when Top==-1 is empty stack
5.3 Formula-based Representation We may use the Formula-based representation when Top=-1 is empty stack stack 0 1 2 top maxtop-1

5.3 Formula-based Representation Formula-based class stack template class Stack //LIFO objects publiC Stack(int MaxStackSize=10) Stackoi delete stack; 1 bool isemptyoconst return top==--1 bool IsFulloconst return top== Top; 1
5.3 Formula-based Representation • Formula-based class Stack template class Stack { //LIFO objects public: Stack(int MaxStackSize=10); ~Stack(){delete [] stack;} bool IsEmpty()const {return top==-1;} bool IsFull()const{return top==MaxTop;}

5.3 Formula-based Representation T TopOconst Stack & add(const T& x) Stack& delete& x) Private int top; /current top of a stack int MaxTop; //max value for top T* stack; /element array
5.3 Formula-based Representation T Top()const; Stack& Add(const T& x); Stack& Delete(T& x); Private: int top; //current top of a stack int MaxTop; //max value for top T* stack; //element array };

5.3 Formula-based Representation 1)constructor Stack template Stack Stack(int MaxStackSize) (//stack constructor MaxTop-MaxStack Size-l stack-new T[MaxStack Size top=-l
5.3 Formula-based Representation 1)constructor Stack template Stack::Stack(int MaxStackSize) {//stack constructor MaxTop=MaxStackSize-1; stack=new T[MaxStackSize]; top=-1; }

5.3 Formula-based Representation Get the top element Template T Stack: TopOconst f//return top element if(Is empty throw OutofBoundso else return stack[]
5.3 Formula-based Representation 2)get the top element Template T Stack::Top()const {//return top element if(IsEmpty())throw OutOfBounds(); else return stack[top]; }
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《数据结构的算法在C++中的应用》(英文版)Chapter 4 Arrays and Matrix.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 3 Linear List.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 2 Program performance.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 1 preface.ppt
- 《数据结构的算法在C++中的应用》(英文版)Textbook.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第9章 宏.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第8章 数据访问页.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第7章 建立Access报表.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第6章 Access窗体的操作.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第5章 查询的创建及应用.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第4章 建构Access数据库表.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第3章 创建Access数据库.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第2章 Access 2002应用基础.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第1章 数据库原理及基本概念.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第12章 综合实例应用.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第11章 Access数据库的管理.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第10章 Access模块和应用程序设计.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)各章习题参考答案.ppt
- 西北工业大学:《计算机系统结构》总复习及模拟试题.ppt
- 西北工业大学:《计算机系统结构》总复习.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 6 Queue.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 7 Hashing.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 8 Binary and other trees.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 9 Priority Queues.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 11 Search Trees.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 12 Graphs.ppt
- 四川电力职业技术学院:《ASP网络程序设计》目录.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第五章 数据库基础知识.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第二章 ASP初步.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第一章 网络程序设计概述.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第三章 ASP脚本语 VBScript.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第四章 ASP常用内部对象.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第六章 ASP数据库编程.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第八章 使用第三方组件.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第七章 文件存取组件及其它组.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第一章 网络程序设计概述.ppt
- 《ASP动态网页设计》电子教案.doc
- 《ASP动态网页设计》教学大纲.doc
- 《ASP动态网页设计》教学进度表.doc
- 《ASP动态网页设计》进度计划.doc