Question: Write the construction and five basic functions for the STACK listed below by using 2D array to simulate Linked List approach. Details for each function:

Write the construction and five basic functions for the STACK listed below by using 2D array to simulate Linked List approach. Details for each function:

Construction( ): construct an empty 2D array with capacity of 26 to simulate the OS.

1.Empty( ): test if the STACK is empty

2.Push(element): Add a value at the top of the stack of the 2D array.

3.Top( ): Read the value at the top of the stack

4.Pop( ): Remove the value at the top of the stack

5.Display( ): Displays all the elements in the stack using from Top to Bottom ordering. (Show array index, data value, and next array index)

After you finished the six functions, create an empty stack (with capacity=26) and then start push 10 values (1,2,3,4,5,6,7,8,9,10) by Push( ) consecutively. After that, you will have 10 elements in your STACK. Run Display ( ) to print out the STACK. Then perform 3 times of Push( ) of value (20,30,40) on valid positions, run Display( ) to print out the list every time you insert a new element. Then perform 3 times of Top() and Pop( ), again, run Display( ) to print our the list every time you delete an element.

To visualize the requirement, the code should looks like:

Push(1)

Push(2)

Push(3)

Push(4)

Push(5)

Push(6)

Push(7)

Push(8)

Push(9)

Push(10)

Display()

Push(20)

Display()

Push(30)

Display()

Push(40)

Display()

Top()

Pop()

Display()

Top()

Pop()

Display()

Top()

Pop()

Display()

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!