12943 - Implement Stack Using Linked List   

Description

Please use the provided two files, main.c and function.h, to implement a stack. Includes following functions:

  1. Push: insert an element into a stack.
  2. Pop: remove the last element from a stack.
  3. Peek the last element: print the last element’s value inside a stack.
  4. Check if it is empty: Check if a stack is empty.

Note:

  1. A Stack data structure shold follow LIFO(last in first out) rule.
  2. Print nothing if there is no elements.

Go download function.c, and only need to submit function.c.

Input

Legal commands:

  1. “push” with an integer N in a new line: Insert an element which value is N into the stack.
  2. “pop”: remove the last element inside the stack and return its pointer.
  3. “top”: print the last element inside the stack.
  4. “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.c

Partial Judge Header

12943.h

Tags




Discuss