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

📄 bstack.h

📁 多进制输出。输入一个非负的10进制数和一个相应的数字
💻 H
字号:
#include <iostream>
using namespace std;
const int MAXSTACKSIZE=50;
template <typename T>
class bstack
{
	public:
		bstack()
		{
//		 T stacklist[MAXSTACKSIZE];
			 topIndex=-1;
		}

	    void push(const T& item)
		{  
			if(!full())
			{
				topIndex++;
				stacklist[topIndex]=item;
			}
			else
				cout<<"overflowError"<<endl;
		}
		void pop()
		{  if(!empty())
			 topIndex--;
		   else 
			 cout<<"underflowError"<<endl;
		}

		T& top()
		{  
			if(!empty())			
			   return stacklist[topIndex];			
			else
		       cout<<"underflowError"<<endl;
		}
		const T& top() const
		{
		if(!empty())			
			   return stacklist[topIndex];			
			else
		       cout<<"underflowError"<<endl;
		}
		bool empty() const
		{ 
			if(topIndex==-1)
				return  true;
			else 
				return false;
		}
		int size() const
		{
			return (topIndex+1);
		}
		bool full()const
		{
			if(topIndex==MAXSTACKSIZE)
				return true;
			else 
				return false;
		}
	private:
		T stacklist[MAXSTACKSIZE];
		int topIndex;

};

⌨️ 快捷键说明

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