12594 - Implement Linked List   

Description

Given a link list structure named Node.

typedef struct _Node {

    int data;

    struct _Node *next;

} Node;

In this problem, you need to implement five operation 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);

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 

Note: We guarantee that function 1, 3~5 will not operate on an empty list.

Input

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

(0: push_front, 1: clone, 2: delete, 3: swap)

Hint: 

testcase1 : contain only createList operation

testcase2: contain only push_front operation

testcase3: contain createList , push_front, copyList operation

testcase4: contain createList , push_front , copyList operation, deleteElementByIdx

testcase5: contain all operation 

Output

Output the element in linked list whenever the operation be called. 

Sample Input  Download

Sample Output  Download

Partial Judge Code

12594.c

Partial Judge Header

12594.h

Tags




Discuss