我需要实现缀到后缀转换算法来计算表达式a + b *的CD/E需要创建缀以后缀算法
我还需要做到这一点使用队列(我相信2个不同的队列堆栈是需要)
我使用DoubleLinkList创建了队列类,现在只需要创建这个问题的算法。尽管如此,但我对于如何解决这个问题却很失落。任何帮助,将不胜感激!
至今(我知道这是非常错误的),我有:
string infix = "a+b*c-d/e";
Queue *holder = new Queue();
Queue *newstring = new Queue();
int length = infix.length();
char temp;
char prev;
for(int i=0; i<length; i++)
{
temp = infix[i];
if((temp == '+') || (temp == '-') || (temp == '*') || (temp == '/'))
{
if (holder->isEmpty())
{
holder->queue(temp);
}
if(temp<holder.enqueue())
{
}
}
holder->queue(temp);
}
快速谷歌搜索 “转换到缀后缀” 产生[本内容丰富的文章(http://scriptasylum.com/tutorials/infix_postfix /algorithms/infix-postfix/index.htm)。你可能想从那里开始。 – 2013-03-14 17:32:33