Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

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_2

Step: 3

blur-text-image_3

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

Students also viewed these Databases questions

Question

Have issues been prioritized?

Answered: 1 week ago

Question

Has the priority order been provided by someone else?

Answered: 1 week ago

Question

Compare the current team to the ideal team.

Answered: 1 week ago