Question
Write java code to convert the following statement into Postfix Expression using a stack data structure. ( *** Don't use Java's stack !!!*****) 1+2*3+4*5+6 ***
Write java code to convert the following statement into Postfix Expression using a stack data structure. ( *** Don't use Java's stack !!!*****)
1+2*3+4*5+6 ***
Don't use Java's stack !!!*****
**I wrote some incomplete code**
public class Evaluation2 { static String inf = "1+2*3+4+5+6"; static int stackTop; static char[] myStack = new char[40]; public static void main(String[] args) { } static void inToPost(String s ){ Evaluation2 myStack = new Evaluation2(); String post =""; for ( int i = 0; i < s.length(); i++) { char c = s.charAt(i); if ( c == '(') { myStack.Push(c); System.out.println("pushing ( "); } else if ( c == ')') { char top = myStack.myStack[myStack.stackTop]; while (!(myStack.isEmpty()) && !(top == '(')) { myStack.Pop(); post += top; if ( !(myStack.isEmpty())) { top = myStack.myStack[myStack.stackTop]; } System.out.println("popping " + top); } myStack.Pop(); } static void Push(char c ) { stackTop++; myStack[stackTop] =c; } static char Pop() { char c = myStack[stackTop]; stackTop--; return c ; } public static boolean isEmpty() { if (stackTop < 0) return true; else return false; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started