12943 - Implement Stack Using Linked List
|
Time |
Memory |
| Case 1 |
1 sec |
32 MB |
| Case 2 |
1 sec |
32 MB |
| Case 3 |
1 sec |
32 MB |
| Case 4 |
1 sec |
32 MB |
| Case 5 |
1 sec |
32 MB |
Description
Please use the provided two files, main.c and function.h, to implement a stack. Includes following functions:
- Push: insert an element into a stack.
- Pop: remove the last element from a stack.
- Peek the last element: print the last element’s value inside a stack.
- Check if it is empty: Check if a stack is empty.
Note:
- A Stack data structure shold follow LIFO(last in first out) rule.
- Print nothing if there is no elements.
Go download function.c, and only need to submit function.c.
Input
Legal commands:
- “push” with an integer N in a new line: Insert an element which value is N into the stack.
- “pop”: remove the last element inside the stack and return its pointer.
- “top”: print the last element inside the stack.
- “isempty?”: Check if the stack is empty.
Output
No need to handle output. Please use function.c above.
Partial Judge Code
12943.c
Partial Judge Header
12943.h
Tags