Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercises 1-2 ask you to add some function members to one of the Stack classes i

ID: 3533079 • Letter: E

Question

Exercises 1-2 ask you to add some function members to one of the Stack classes in

this section. You may use either of the array-based implementations-the static array

version or the dynamic array version.

1. Write documentation, a prototype, and a definition for a member function

bottom() for the Stack class that returns the bottom element of the stack.

2. Repeat Exercise 6, but for a function bottom() that is neither a member function

nor a friend function of the Stack class.

______________________________________________________________________________

In Exercises 1 adn 2, assume that a = 7.0, b = 4.0, c = 3.0, and d = -2.0. Evaluate the

postfix expression.

1. a b + c / d *

2. abc - - d -

___________________________________________________________________________

For the postfix expressions in Exercise 1, trace the algorithm for evaluating

postfix expressions by showing the contents of the stack immediately before each of

the tokens marked with a caret is read. Also, give the value of the postfix expression.

1. 32 5 3 + / 5 *

_______________________________________________________________________

Convert the infix expressions in Exercises 1-2 to postfix.

1. a * b + c - d

2. a - (b - (c - (d - e)))

__________________________________________________________________________

For the infix expressions in Exercise 1 below, trace the algorithm for converting infix

to postfix by showing both the stack and the accumulated output immediately before

each of the tokens marked with a caret is read. Also, show the postfix expression.

1. a + b / c - d

__________________________________________________________________________

Convert the postfix expressions in Exercises 1 below to infix notation:

28. a b c + - d *

Explanation / Answer

1) public int bottom(Stack S)

{

Stack Ns=new Stack();

Ns=S;

int bottom;

while(!Ns.isEmpty())

{

bottom= Ns.Pop();

}

return bottom;

}



2)

a b + c / d * postfix

is equivalent to

*

d

+ c

a b

or (a+b)d/c=-22/3

3) Infix

a + b / c - d is equivalent to

(a+b)/c -d

Now postfix of above is

a b + c / d -


4) Postfix

a b c + - d * is equivalent to

=>(( a(b c +)-) d *)

=> (a-(b+c))* d infix form


If you want others,plz comment


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote