11723 - 231001_12/7_practice12-2   

Description

Finish the following 5 functions to finish the stack problem

(1.) void stack_init(struct stack *s, int size)

Do the following 3 things:

   1. Allocate memory to stack_ptr by creating a     dynamic  memory with size size.

   2. set top to 0;

   3. set max_size to size;

(2.) void stack_destroy(struct stack *s)

Free memory

(3.) void push(int elem, struct stack *s)

You need to check whether the stack is full before pushing into the stack.

1. If it's full, print "Stack is full!\n" on the screen.

2. Otherwise, push elem into stack, and remember doing top++ to record how many numbers has been pushed.

(4.) void show_stack(struct stack *s)

You need to check whether the stack is empty.

1. If it's empty, print "Empty" on the screen.

2. Otherwise, print all elements in the stack separated by a whitespace.

(5.) int pop(struct stack *s)

You need to check whether the stack is empty before popping.

1. If it's empty, print "Stack is empty!\n" on the screen and return -100000.

2. Otherwise, pop the latest element from the stack and return it.

Input

Input: An integer n

Output

See the sample I/O

Sample Input  Download

Sample Output  Download

Tags




Discuss