Answered step by step
Verified Expert Solution
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
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 #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started