Question: Implement the following function. You may use the stack template class (pasted below) and the stack operations of push, pop, peek, is_empty, and size. You

Implement the following function. You may use the stack template class (pasted below) and the stack operations of push, pop, peek, is_empty, and size. You may also use cin.peek( ) and use "cin>>i" to read an integer.

int evaluate_postfix_from_cin( )

// Precondition (Which is not checked): The next input line of cin is a properly formed postfix expression consisting of integers and the binary operations

// Postcondition: The function has read the next input line (including the newline) and returned the value of the postfix expression.

Test it in the main()

// FILE: stack1.template // This file is included in the header file, and not compiled separately. // INVARIANT for the stack class: // 1. The number of items in the stack is in the member variable used. // 2. The actual items of the stack are stored in a partially-filled // array data[0]..data[used-1]. The stack elements appear from the // bottom (at data[0]) to the top (at data[used-1]).

#include // Provides assert

namespace main_savitch_7A { template const typename stack::size_type stack::CAPACITY; template void stack::push(const Item& entry) // Library facilities used: cassert { assert(size( ) < CAPACITY); data[used] = entry; ++used; } template void stack::pop( ) // Library facilities used: cassert { assert(!empty( )); --used; }

template Item stack::top( ) const // Library facilities used: cassert { assert(!empty( )); return data[used-1]; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!