Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions

Question

politeness and modesty, as well as indirectness;

Answered: 1 week ago