Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pseudo code: For each token, t: If t is a number: push (t) Else

 imageimage

Pseudo code:

 

For each token, t:

If t is a number:

    push (t)

Else 

                 Arg2 = pop();

      Arg1 = pop();

      Result = arg1 +  't' +  arg2; 

      push(result)

End if

End for 

Return pop()


 

 

Convert this pseudo code into java code using this file, complete the push and pop methods using the stack implement in the file. Problem description is provided above:

 

public class LinkedStack {      private class Node {          Node next;          T data;            Node(T e, Node nxt) {              data = e;              next = nxt;          }      }        private Node head = null;        public LinkedStack() { }        /*       * Pushes an item onto the top of this stack.       * Parameters:       *   item - the item to be pushed onto this stack.       * Returns:       *   the item argument.       */      public T push(T item) {          /*           * YOUR CODE HERE           */          return item;      }        /*       * Removes the object at the top of this stack and returns that object as       *   the value of this function.  null is returned if stack is empty       * Returns:       *   The object at the top of this stack or null if stack is empty       */      public T pop() {          /*           * YOUR CODE HERE           */          return null; // This line will change      }        /*       * Tests if this stack is empty.       * Parameters:       *   o - element whose presence in this set is to be tested       * Returns:       *   true if and only if this stack contains no items; false otherwise.       */      public boolean empty() {          return head == null;      }  }

Postfix Expressions Background: Suppose we wanted to evaluate a postfix expression such as 12 +34 + *7/ which in regular infix notation looks like ((1+2) * (3+4))/7 The challenge is that we may have many nested operations. Problem: You need to write an evaluator for these kinds of expressions. Give an algorithm that takes a postfix expression and outputs the result of the expression. Hint: You will need a stack for this! input: LList of numbers, operators and parentheses output: result of expression

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Determine miller indices of plane X z 2/3 90% a/3

Answered: 1 week ago