data structure--Stack(基于数组实现)
来源:互联网 发布:头像源码怎么用 编辑:程序博客网 时间:2024/06/06 00:18
#include<iostream>using namespace std;const int maxstack=10;template <class T>class ArrayStack{public:ArrayStack();T& top();void pop();void push(T&);bool IsEmpty() const;bool full() const;void clear();int size() const;private: int current;T array[maxstack];};template <class T>ArrayStack<T>::ArrayStack()/*Pre: None Post: The stack is initialized to be empty.*/{ current=-1;}template <class T>void ArrayStack<T>::push(T &item)/*Pre:None Post:If the stack is not full,item is added to the top of the ArrayStack. Else,the stack is left unchanged.*/{if(current<maxstack-1) array[++current]=item;}template <class T>void ArrayStack<T>::pop()/*Pre:None Post:If the stack is not empty,the top of the ArrayStack is removed. Else,the stack is left unchanged.*/{if(!IsEmpty()) current--;}template <class T>T& ArrayStack<T>::top()/*Pre:None Post:If the stack is not empty,the top of the ArrayStack is returned.*/{ if(!IsEmpty()) return array[current]; }template <class T>bool ArrayStack<T>::IsEmpty() const/*Pre:None Post:If the stack is empty,true is returned.Otherwise,false is returned*/{ if(current==-1) return 1; else return 0;}template <class T>bool ArrayStack<T>::full() const/*Pre:None Post:If the stack is full,true is returned.Otherwise,false is returned*/{return current==9;}template <class T>int ArrayStack<T>::size() const/*Pre:None Post:Return the number of entries in the stack.*/{return (current+1);}template <class T>void ArrayStack<T>::clear()/*Pre:None Post:Reset the stack to be empty*/{current=-1;}
0 0
- data structure--Stack(基于数组实现)
- data structure --Queue(基于数组的实现)
- The Stack Data Structure
- Data Structure:stack
- Stack & Queue--Data Structure
- 【Data Structure】树状数组
- Data Structure-2 Queue 循环队列,用数组实现
- introduction to algorithms data structure lesson_1 stack
- UVA11995I Can Guess the Data Structure!(stack + queue + priority_queue)
- 数据结构(Data Structure)——1、栈(Stack)
- HDU 4217 Data Structure? 树状数组
- hdu 4217 Data Structure?(树状数组)
- Hdu 4217 Data Structure?【二分+树状数组】
- 基于数组实现Java 自定义Stack栈类及应用
- 【Data Structure/Algorithm】LCSS算法实现
- Data Structure
- Data structure
- Data Structure
- android 9patch背景图片导致的一个文本显示问题
- 大量存在于iptables模块中的BUG
- webim即时通讯解决方案
- linux 内核定时器 timer_list详解
- 我的Hook学习笔记
- data structure--Stack(基于数组实现)
- Mac装windows系统
- linux技巧:使用 screen 管理你的远程会话
- C语言栈、堆和静态区
- SVN的基本安装使用方法
- 黑马程序员_关于银行业务调度系统的设计思路
- 2.SQL Server DML触发器之COMMIT和ROLLBACK TRANSACTION
- ImportError: No module named Image IOError: decoder zip not available
- OnCreate 函数的说明