stack.h

来自「该计算器比较实用」· C头文件 代码 · 共 60 行

H
60
字号
#ifndef Stack_SFSFSF
#define Stack_SFSFSF
#include<iostream>
#include<string>
using namespace std;

template<class entrytype> 
class Stack{
public:
	Stack();
	bool empty() const;
           int get_top(entrytype &) const;
	       int push(const entrytype x);
	       int pop();
	bool full() const;
private:
	entrytype data[100];
	int count;
};

template<class entrytype> 
Stack<entrytype>::Stack() {count=0;}

template<class entrytype> 
bool Stack<entrytype>::empty() const{
	if(count==0) return true;
	else return false;
}

template<class entrytype> 
int Stack<entrytype>::get_top(entrytype &x) const{
	if(empty()) return 0;
	else{
		x=data[count-1];
		return 0;
	}
}

template<class entrytype> 
int Stack<entrytype>::push(const entrytype x){
	if(full()) return 1;
	else{
		data[count++]=x; 
	    return 0;
	}
}

template<class entrytype> 
int Stack<entrytype>::pop(){
	if(empty()) return 1;
	else count--;
	return 0;
}

template<class entrytype> 
bool Stack<entrytype>::full() const {
	if(count==100) return true;
	else return false;
}
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?