2 Kasım 2009 Pazartesi

Postfix ifadelerin sonucunu hesaplayan algoritma

Algoritma : (Bir postfix ifadenin sonucunu hesaplar)
opndstk = the empty stack;
// scan the input string reading one element at a time into symb
while (not end of input) {
symb = next input character;
if (symb is an operand)
push(opndstk,symb);
else {
// symb is an operator
opnd2 = pop(opndstk);
opnd1 = pop(opndstk);
value = result of applying symb (case *,/,+,-) to opnd1 and opnd2
push(opndstk,value);
} // end else
} // end while
return(pop(opndstk));

Hiç yorum yok:

Yorum Gönder