Given a link list structure named Node.
typedef struct _Node {
int data;
struct _Node *next;
} Node;
In this problem, you need to implement seven operations for the linked list.
func1: Node* createList(int *a, int size);
func2: void push_front(Node** head, int val);
func3: Node* copyList(Node* head);
func4: void deleteElementByIdx(Node** head, int idx);
func5: void SwapElementByIdx(Node** head, int idx1, int idx2);
func6: void ReverseList(Node** head);
func7: void ShiftListByK(Node ** head, int k);
func1: using an array to build the link list
func2: append the input value to the first element in the linked list
ex: origin linked list : [0, 1, 2, 3], when call the function push_front(&head, 5). the final linked list will be [5 ,0 ,1, 2, 3]
func3: copy the original link list (not directly to assign it)
func4: delete the element by its index (begin from 0)
ex: origin linked list : [0, 1, 2, 3], when call the function deleteElementByIdx(&head, 0). the final linked list will be [1,2,3]
note that: if the idx out of range. you should ignore the delete operation
func5: swap the element in linked list by given idx1 and idx2 (both begin from 0)
ex: origin linked list: [0, 1, 2, 3], when call the function SwapElementByIdx(&head, 0, 3). the final linked list will be [3, 1, 2, 0]
note that: if the idx1 or idx2 out of range, you should ignore the swap operation
func6: reverse the linked list.
ex: origin linked list: [0, 1, 2, 3],when call function ReverseList(&head), the final linked list will be [3, 2, 1, 0]
func7: right shift the linked list by the given integer K.
ex: origin linked list: [0, 1, 2, 3], K: 1, when call function ShiftListByK(&head, 1), the final linked list will be [3, 0, 1, 2].
Note: We guarantee that function 1, 3~7 will not operate on an empty list.
T M
S1 .. SM
t1_command
...
tT_command
T: the number of command ( 0 <= T < 200)
M: the number of initial linked size (0 <= M <= 2000)
Si: the value of the initial array (0 <= Si <= 1000)
ti_command: the command description
K: the value of the shift length for the function 7 (0 <= K <= 10^9)
(0: push_front, 1: clone, 2: delete, 3: swap, 4: reverse, 5: shift)
Hint:
testcase1 : contain only function 1
testcase2: contain only function 2
testcase3: contain function 1~3
testcase4: contain function 1~4
testcase5: contain function 1~5
testcase6: contain only function 1,6
testcase7: contain only function 1.6,7
testcase8: contain all functions
Output the element in linked list whenever the operation be called.