12438 - DS_2019Fall_Linked List (practice)   

Description

Implement some operations used in a linked list

ex. insert, delete, reverse, swap, rotate, print

  1. InsertBack data: insert a node with data to the end of the linked list.
  2. InsertFront data: insert a node with data to the front of the linked list.
  3. InsertAfter data ref: insert a node with data after the existing node with ref in the linked list.
  4. InsertBefore data ref: insert a node with data before the existing node with ref in the linked list.
  5. 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).
  6. DeleteFront: delete the first node in the linked list.
  7. DeleteBack: delete the last node in the linked list.
  8. Reverse: reverse the nodes order of the linked list.
  9. Rotate k: put the last k nodes into the front (if k>total nodes, then k=k%total).
  10. 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).
  11. 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 ‘->’.

Sample Input  Download

Sample Output  Download

Tags

hi oh yeak linked_list_so_annoy meow 清大高爾軒 NTHU_THE_ROCK 陳博偉是大神



Discuss