⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tempzhan1.h

📁 计算器 WINDOWS MFC的计算器 加减乘除都可以
💻 H
字号:
#ifndef STACK_CLASS
#define STACK_CLASS
#include <iostream.h>
#include <stdlib.h>
const int MaxStackSize=50;
template <class T>
class Stack
{
	private:
		 T stacklist[MaxStackSize];
		 int top;
	public:
		Stack(void);
		void push(const T& item);
		T pop(void);
		void clearstack(void);
		T peek(void)const;
		int stackempty(void)const;
		int stackfull(void)const;
};
template <class T>
Stack<T>::Stack(void)
{top=-1; }
template <class T>
void Stack<T>::push(const T& item)
{
	if(top==MaxStackSize-1)
	{ //cerr<<"stack over flow!"<<endl;
	 exit(1);
	}
	top++;
	stacklist[top]=item;

}
template <class T>
T Stack<T>::pop(void)
{
	T temp;
	if(top==-1)
	{ //cerr<<"attempt to pop an empty stack!"<< endl;
	 exit(1);
	}
	temp=stacklist[top];
	top--;
	return temp;
}

template <class T>
T Stack<T>::peek(void)const
{
if(top==-1)
{
	// cerr<<"attempt to peek at an empty stack!"<< endl;
	 exit(1);
}
return stacklist[top];
}

template <class T>
int  Stack<T>::stackempty(void)const
{
	return top==-1;
}

template <class T>
void Stack<T>::clearstack(void)
{ top=-1;}

template <class T>
int Stack<T>::stackfull(void)const
{retrun top==MaxStackSize-1;}

#endif  //STACK_CLASS

⌨️ 快捷键说明

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