首页 > 代码库 > Infix expressions 中缀表达式

Infix expressions 中缀表达式

中缀表达式的计算

利用两个栈来实现,操作数栈,操作符栈

只支持个位数运算

最后必须输入一个‘#‘

#include<iostream>using namespace std;template<typename ElementType>struct Node{	ElementType data;	Node<ElementType>* next;};template<typename ElementType>class LinkStack{public:	LinkStack()	{		top = new Node<ElementType>;		top = NULL;	}	~LinkStack()	{		delete top;	}	void push(ElementType item);	void pop();	ElementType front() const;private:	Node<ElementType>*top;};template<typename ElementType>void LinkStack<ElementType>::push(ElementType item){	Node<ElementType>*p = new Node<ElementType>;	p->data = http://www.mamicode.com/item;"input the infix expression:(you must input # to stop input)" << endl;	LinkStack<char>* SOPTR = new LinkStack<char>;	LinkStack<int>* SOPND = new LinkStack<int>;	evaluate(SOPTR,SOPND);	return 0;}

Infix expressions 中缀表达式