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

📄 stack.h

📁 把中缀表达式转换为后缀表达后
💻 H
字号:
#ifndef STACK_H_
#define STACK_H_
#include"Node.h"

/****************************************************************/
template<class Stack_entry>
class Stack{
public:
	Stack();
	bool empty()const;
	Error_code push(const Stack_entry &item);
	Error_code pop();
	Error_code top(Stack_entry &item)const;
	int size();
	~Stack();
protected:
	Node<Stack_entry>*top_node;
	int count;
};

/****************************************************************/
template<class Stack_entry>
Error_code Stack<Stack_entry>::push(const Stack_entry &item){
	Node<Stack_entry> *new_top=new Node<Stack_entry>(item,top_node);
	if(new_top==NULL)
		return overflow;
	top_node=new_top;
	count++;
	return success;
}
/*************************************************************/
template<class Stack_entry>
Error_code Stack<Stack_entry>::pop(){
	Node<Stack_entry> *old_top=top_node;
	if(top_node==NULL)
		return underflow;
	top_node=top_node->next;
	delete old_top;
	count--;
	return success;
}
/*************************************************************/
template<class Stack_entry>
Error_code Stack<Stack_entry>::top(Stack_entry &item)const{
	if(top_node==NULL)
		return underflow;
	item=top_node->entry;
	return success;
}
/*************************************************************/
template<class Stack_entry>
int Stack<Stack_entry>::size(){
	return count;
}
/*************************************************************/
template<class Stack_entry>
Stack<Stack_entry>::Stack(){
	top_node=NULL;
	count=0;
}
/*************************************************************/
template<class Stack_entry>
Stack<Stack_entry>::~Stack(){
	while(!empty())
		pop();
}
/*************************************************************/
template<class Stack_entry>
bool Stack<Stack_entry>::empty()const{
	return top_node==NULL;
}
/*************************************************************/
#endif

⌨️ 快捷键说明

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