| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11283 | rotate linked list |
|
| 11336 | Linked list - deletion & insertion |
|
Description
Given a link list structure named Node.
typedef struct _Node {
int data;
struct _Node *next;
} Node;
Given a list, rotate the list to the left by k places, where k is non-negative and k is smaller than the count of nodes in linked list.
For example:
Given 1->2->3->4->5->NULL and k = 3,
return 4->5->1->2->3->NULL.
Input
The input contains 2 sequence of positive integers.The first sequence is to create a linked list of integers, except the last one, which is -1, indicating the end of the sequence. The second line is an integer k.
Output
The output contains the sequence of resulting linklist.
Sample Input Download
Sample Output Download
Partial Judge Code
11283.cPartial Judge Header
11283.hTags
Discuss
Description
This problem asks you:
- To create a linked list to store a sequence of positive integers.
- To delete some given integers in the linked list. If the node is not existing, do nothing.
- To insert an integer into an appropriate position in the linked list.
For example, if the input is
1 2 3 4 5 6 7 -1
1 1 4 -1
2
1 8
3 9
The first sequence is 1 2 3 4 5 6 7 -1, so a linked list is created as

The second sequence is 1 1 4 -1, so do the follows.
After p1=1, the list becomes

because the first node is 1.
After p2 = 1, the list becomes

because the first node is 2.
After p3 = 4, the list becomes

because the fourth node is 6.
The next number is 2, so you need to read two lines.
The first line is 1 8, so the data of new node is 8 and should be inserted at position 1. The list becomes

The second line is 3 9, so the data of new node is 9 and should be inserted at position 3. The list becomes

Finally, the answer is 8 3 9 4 5 7.
Note for those who are not familiar with partial judge:
You will be provided with main.c and function.h, and asked to implement function.c containing three function createList, deleteNode and insertNode.
For OJ submission:
Step 1. Submit only your function.c into the submission block. (Please choose c compiler)
Step 2. Check the results and debug your program if necessary.
Input
The input contains 3 parts:
1. A sequence of positive integers as the linked list, except the last one, which is -1.
2. A sequence of positive integers as the position need to be deleted, except the last one, which is -1.
3. A number N means the number of inserted node, and next N lines contain a pair of number (X, Y). X is the position which you are asked to insert a new node into and Y is the data of the node.
Output
The output contains the sequence of resulting linklist.