11876 - Linked List (for the EE class)
|
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 |
| Case 6 |
1 sec |
32 MB |
| Case 7 |
1 sec |
32 MB |
| Case 8 |
1 sec |
32 MB |
| Case 9 |
1 sec |
32 MB |
| Case 10 |
1 sec |
32 MB |
Description
- 一定要用自己寫的linked list完成作業,不可以使用array,也不可以#include<list>或使用類似的現成 libraray
- 不過STL list非常好用,雖然不能用於此作業,仍可以學習 https://www.cprogramming.com/tutorial/stl/stllist.html
- 第一個測資就是sample input/output
Implement a linked list to store Christmas gifts.
- Each node stores a gift and its corresponding price
- Price ranges from 0 to 999
- Each gift price is unique, two duplicate prices will not exist at the same time
You should implement 4 operations below
- InsertBack(gift, price)
- Insert a gift to the end of the linked list
-
Example:
Original list: (Candy,50)->(book,350)
After InsertBack(Toy, 120)
Updated list (Candy,50)->(book,350)->(Toy,120)
- InsertAfter(gift, price, priceToInsertAfter)
-
If priceToInsertAfter does not exist in the linked list, do nothing
-
Example1:
Original list: (Candy,50)->(book,350)
After InsertAfter(Toy, 120, 50)
Updated list: (Candy,50)->(Toy,120)->(book,350)
-
Example2:
Original list: (Candy, 50)->(book,350)
After InsertAfter(Toy, 120, 70)
Updated list: (Candy, 50)->(book,350)
- Delete (price)
- Remove the gift matched the input price from the linked list
-
If this price does not exist in the linked list, do nothing
-
Example1:
Original list: (Candy,50)->(book,350)
After Delete(50)
Updated list: (book,350)
-
Example2:
Original list: (Candy,50)->(book,350)
After Delete(20)
Updated list: (Candy,50)->(book,350)
- Reverse()
- Reverse the linked list
-
Example:
Original list: (Candy,50)->(book,350)
After Reverse()
Updated list: (book,350)->(Candy,50)
Input
One (not many) sequence of operations. Each line describes one operation.
The last line is "End".
Output
Print "Empty" or "List" first.
If not empty, then print the entire list of gifts and their corresponding prices.
- Connect with symbols “->”
- No space in between
Tags