Question: language c++ Aim: Write a program to create a Stack and different functionality related to it as stated above and implement it using one dimensional


language c++
Aim: Write a program to create a Stack and different functionality related to it as stated above and implement it using one dimensional Array. Description: Here STACK is an array with STACKSIZE locations. TOP points to the top most element and ITEM is the value to be inserted. Algorithm for PUSH using array: Algorithm: PUSHO [STACK already filled?] 1. If TOPESTACKSIZE-1, then: Print: OVERFLOW / Stack Full, and End. 2. Set TOP = TOP+1. [Increase TOP by 1.) 3. Set STACK[TOP]=ITEM. [Insert ITEM in new TOP position.] 4. End. Algorithm for POP using array: Description: Here STACK is an array with STACKSIZE locations. TOP points to the top most element. This procedure deletes the top element of STACK and assigns it to the variable ITEM. Algorithm: POPO [Does STACK has an item to be removed? Check for empty stack] 1. If TOP=-1, then Print: UNDERFLOW/ Stack is empty, and End. 2. Set ITEM = STACK[TOP]. [Assign TOP element to ITEM.] 3. Set TOP-TOP-1. [Decrease TOP by 1.] 4. End. Algorithm for PEAK using array: Description: Here STACK is an array with STACKSIZE locations. TOP points to the top most element. This procedure produces the top element of STACK and assigns it to the variable ITEM without removing it. Algorithm: PEAKO [Does STACK has an item to Peak? Check for empty stack] 1. If TOP=-1, then Print: UNDERFLOW/ Stack is empty, and End. 2. Set ITEM = STACK[TOP]. [Assign TOP element to ITEM.] 3. End. Algorithm for Traverse STACK implemented as array: Description: Here STACK is an array with STACKSIZE locations. TOP points to the top most element. This procedure produces all the values ( pushed on stack ) without removing them. Algorithm: Traverse() [Does STACK has any item to Traverse? Check for empty stack] 1. If TOP=-1, then Print: UNDERFLOW/ Stack is empty, and End. 2. T = TOP ( Put TOP into T so that its value not to be changed ] 3. Repeat While T20 a) Write: STACK[T] b) Set T = T-1 [End of Loop of step-3.] 4. End
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
