Question: Write a C language program. The following code will implement three functions supported by a stack. Push ( ): It adds element an on top

Write a C language program.

The following code will implement three functions supported by a stack.

Push ( ): It adds element an on top of the stack. It takes O (1) O (1) time as each element is inserted starting from the table of the array; there is no need to shift existing elements to make room for the new element.

Pop (): It removes the element on top of the stack. It also takes O (1) O (1) time as the top contains the index of the most recently added element.

Top (): It returns the element on top of the stack. It takes O (1) O (1) time as finding the value stored at a particular index in an array is a constant time operation.

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!