problems on postfix conversion
i have a problem on converting infix to postfix evaluation and appending the characters in the string if the character is a digit
Code:
#include <iostream.h>
#include "D:/turboc/bin/stack.h"
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void main()
{
clrscr();
Stack *stack=new Stack(100);
char x[100] ;
cout<<"Input Equation: ";
gets(x);
char dest[100];
for(int i=0;i<strlen(x);i++)
{
if(isdigit(x[i]))
{
cout<<x[i]; //this must append from the string dest
}
else if((x[i]=='+')||(x[i]=='-')||(x[i]=='*')||(x[i]=='/'))
{
stack->push(x[i]);
}
else if(x[i]==')')
{
cout<<stack->pop(); //this must append from the string dest
}
}
cout<<"\n\nPress any key to exit";
getch();
}
the string dest used in evaluation of a postfix
if i input as 2(3+6) the result instead of 236+*, it becomes 236+. the first result applies if the input is (2*(3+6)). which lines of code should be edited and why? and how to append a character array and a character popped from the stack into the string? and also, can this code worked with longer equations?why?
I HOPE you will find the way to correct that problem......
NOTE:files attached below are .txt files containing c/c++ codes and it should be runnable in TurboC