Question: Stack is a common data structure, and its data entry and exit type is the more advanced, the later (FILO). Stack is mainly operated by
Stack is a common data structure, and its data entry and exit type is the more advanced, the later (FILO). Stack is mainly operated by two functions, one is push and the other is pop. Please design one The program uses indicators to implement Stack, allowing users to operate Stack and output the current elements in Stack. The user can have the following two input methods: 1. Number 1 + space + number N: This input method is push, when the user is detected before the input is At 1 o'clock, use the following number N as the number to be pushed into the Stack, put it into the Stack, and refresh the Stack status. Ex: (1 23), (1 5), (1 45)... 2. Number 2: This type of input method is pop. When it is detected that the user's previous input is 2, the Stack Take out the top element in the middle and refresh the status of Stack. Ex: (2). The user must be allowed to enter infinitely, and it will not stop until after EOF. The program must contain two functions formula: 1. void mypush(int): Pass in an integer N, which will be pushed to Stack. 2. int mypop(): Remove the top element in the Stack and return the value inside. This function must To make a judgment, when there are no elements in the Stack that can be taken out, an error message must be returned, which can be beneficial. Use the return -1 to complete. Note: The built-in push and pop cannot be used for this operation. Note: There will be no input errors in the test data, so you don't need to foolproof.

Please input the instruction:1 444 push 444 into stack. Example: Nothing in stack Please input the instruction:2 Error pop Nothing in stack. Please input the instruction:1 3 push 3 into stack. 3 444 20 Please input the instruction:1 5 push 5 into stack. 5 Please input the instruction:1 9 push 9 into stack. 9 OPPOPPER Please input the instruction:1 20 push 20 into stack. 20 444 20 5 Please input the instruction:1 444 push 444 into stack. Please input the instruction:2 pop 9 from stack
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
