12920 - Implement Queue 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 queue. Includes following functions:
- Enqueue: insert an element into a queue.
- Dequeue: remove an element from a queue.
- Print the first element: print the first element’s value inside a queue.
- Print the last element: print the last element’s value inside a queue.
- Check if it is empty: Check if a queue is empty.
Note that:
- A Queue data structure shold follow FIFO(first in first out) rule.
- The first element means the first insert element, and the last element means the latest insert element.
- Print nothing if there is no first element and the last element.
Go download function.c, and only need to submit function.c.
Input
Legal commands:
- “enqueue” with an integer N in a new line: Insert an element which value is N into the queue.
- “dequeue”: remove the first element inside the queue and return its pointer. If the queue is empty return NULL.
- “front”: peak the first element inside the queue and print its value. Print nothing if the queue is empty.
- “back”: peak the last element inside the queue and print its value. Print nothing if the queue is empty.
- “isempty?”: Check if the queue is empty, and print "Yes\n" or "No\n".
- “debug”: You may use this to traversal your queue and check if it’s correct. Use it!!!
Output
No need to handle output. Please use function.c above.
Partial Judge Code
12920.c
Partial Judge Header
12920.h
Tags