Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

language c++ Algorithm to PUSH item on Stack using Linked structure: Algorithm: PUSH(ITEM), [ Here the initial value of TOP is NULL ] 1. Create

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

language c++

Algorithm to PUSH item on Stack using Linked structure: Algorithm: PUSH(ITEM), [ Here the initial value of TOP is NULL ] 1. Create dynamic NODE to store (Info and Next) for top node and store its address into NewNode pointer [Insert ITEM in new TOP position.] 2. Set NewNode -> Info = ITEM and NewNode -> Next = TOP 3. Set TOP = NewNode [ Adjust new TOP address ] 4. End. Algorithm to POP item from Stack using Linked structure: Algorithm: POPO This procedure deletes the TOP element of STACK and assigns its value to the variable ITEM. 1. (Check for empty stack] If TOP = NULL, then Print: UNDERFLOW/ Stack is empty, and End. 2. Set ITEM = TOP -> Info [Assign TOP element to ITEM.] 3. Set T = TOP [Load the address of current TOP into T] 4. TOP TOP -> Next. [Reset TOP by shifting it to lowerext node.] 5. Release T [ Send back the memory occupied by deleted node.] 6. Return ITEM and End Algorithm to produce PEAK item from Stack using Linked structure: Algorithm: PEAKO This procedure Produce the TOP element of STACK without deleting it and assigns its value to the variable ITEM. 1. Check for empty stack] If TOP = NULL, then Print: UNDERFLOW/ Stack is empty, and End. 2. Set ITEM TOP -> Info [Assign TOP element to ITEM.] 3. Return ITEM and End Algorithm to TRAVERSE Stack using Linked structure: Algorithm: TRAVERSE(). This function produces all elements of the STACK without deleting them. 1. [Check for empty stack] IF TOP = NULL, then Print: UNDERFLOW/ Stack is empty, and End. 2. Set T = TOP [Load the address of current TOP into T] 3. Repeat while ( T not NULL) a) Print: T -> Info b) T = T -> Next. [End of Loop of step-3.] 4. End #include #include struct NODE int info; struct NODE *next; }; struct NODE *TOP = NULL; void PUSH (int item) { } int POP ) } int PEAK { } void TRAVERSE() { } bool IsEmpty() { int main() { struct NODE *T; int item, choice; cout"; cin>> choice; switch(choice) { case 1: cout>item; PUSH(item); break; case 2: if(IsEmpty()) {cout

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions