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

📄 stack.h

📁 实现功能(以下命令全部了小写) ls 显示文件目录 chmod 改变文件权限 chown 改变文件拥有者 chgrp 改变文件所属组 pwd 显示当前目录 cd 改变当
💻 H
字号:
#include<iostream>
#include<stdlib.h>
const int MaxStackSize=150;
template<class T>
class Stack
{
private:
	T Stacklist[MaxStackSize];
	int top;
public:
	Stack(void);
	void push(T item);
	T pop(void);
	void ClearStack(void);
	T Peek(void);
	int StackEmpty(void);
	int StackFull(void);
	int recount();
};
template<class T>
Stack<T> ::Stack(void):top(-1){}

template<class T>
void Stack<T> ::push(T item)
{
	if(top==MaxStackSize-1)
	{
		cout<<"Stack overflow!"<<endl;
		exit(1);
	}
	top++;
	Stacklist[top]=item;
	//return Stacklist[top];
}

template<class T>
T Stack<T> ::pop(void)
{
	T temp;
	if(top==-1)
	{
		cout<<"Attempt to pop an empty Stack!"<<endl;
		exit(1);
	}
	temp=Stacklist[top];
	top--;
	return temp;
}

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

template<class T>
T Stack<T> ::Peek(void)
{
	if(top==-1)
	{
		cout<<"Attempt topeek an empty Stack"<<endl;
		exit(1);
	}
	return Stacklist[top];
}

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

template<class T>
int Stack<T> ::StackFull(void)
{
	return top==MaxStackSize-1;
}
template<class T>
int Stack<T> ::recount(void)
{
	int temp;temp=top+1;
	return temp;
}

⌨️ 快捷键说明

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