# | Problem | Pass Rate (passed user / total user) |
---|---|---|
12943 | Implement Stack Using Linked List |
|
12944 | Traversal Linked List in Reverse Order |
|
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.
Sample Input Download
Sample Output Download
Partial Judge Code
12943.cPartial Judge Header
12943.hTags
Discuss
Description
Please use the provided two files, main.c and function.h, to implement methods:
- Insert nodes to a list.
- Traversal a linked list in reverse order.
Go download function.c, and only need to submit function.c.
Input
n
N1 N2 N3 N4 … Nn
Note:
- n represents how many numbers would be provided.
- 32,767 >= n >= 0.
- 32,767 >= N(n) >= -32768.
Output
Output should follow below format:
Print: N1 N2 N3 N4 … Nn
Reverse: Nn Nn-1 Nn-2 … N1
Note that:
- Need to have a return value('\n') at the end of your output.
- Need a ‘Space’ between ‘:’ and N1.
- Need a ‘Space’ between any two numbers.