12438 - DS_2019Fall_Linked List (practice)
|
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 |
1 MB |
Description
Implement some operations used in a linked list
ex. insert, delete, reverse, swap, rotate, print
- InsertBack data: insert a node with data to the end of the linked list.
- InsertFront data: insert a node with data to the front of the linked list.
- InsertAfter data ref: insert a node with data after the existing node with ref in the linked list.
- InsertBefore data ref: insert a node with data before the existing node with ref in the linked list.
- Delete data: delete the node with data (you may need to free the memory).
Please note that our input will ensure that each node holds a distinct integer (data field).
- DeleteFront: delete the first node in the linked list.
- DeleteBack: delete the last node in the linked list.
- Reverse: reverse the nodes order of the linked list.
- Rotate k: put the last k nodes into the front (if k>total nodes, then k=k%total).
- Swap data1 data2: swap the positions of node holding data1 and data2 (if one node doesn’t exist, do nothing). Please note that our input will ensure that each node holds a distinct integer (data field).
- PrintChain: print the data from the first node to the last node in the form of
data1->data2. (we provide an unfinished code and PrintChain has already been implemented).
Input
Each testcase will contain N operations, 0<N<100000.
All integer data are between 0 to 100000.
There are no two nodes with the same data in this problem. That is, we will not have testcase like InsertFront 1, InsertFront 1.
Output
For output operation PrintChain, the form should be 1->2->3->4. Integers (data fields in nodes) are separated by ‘->’.
Tags
hi
oh
yeak
linked_list_so_annoy
meow
清大高爾軒
NTHU_THE_ROCK
陳博偉是大神