This is a partial judge problem.
Given one linked list, you are asked to complete the following two tasks in two different functions:
(1) Partial sort
Given an integer x, you need to put every node which value < x to the front of the linked list.
For example, if x = 4, 7->2->4->1->3->5 will become 2->1->3->7->4->5 after partial sorting.
(Note: You can't change the original relative position between the nodes which value < x and value >= x.)
(2) Split and Swap
Given two integers a and b , you can get two groups: (1) index 0 to index a , (2) index b to index N-1.
All you need to do is swap the two groups. (N is the length of the given linked list)
For example, if a = 1, b = 4, 1->2->3->7->4->5 will become 4->5->3->7->1->2 after the operations.
function.h:
typedef struct _Node {
int data;
struct _Node *next;
} Node;
Node* Partial_sort(Node*, int);
Node* Split_and_Swap(Node*, int, int);
You only need to implement the two functions below in function.h.
First line contains four integers which denote N (the length of given linked list), x, a, b respectively.
(6 <= N <= 10, 1 <= x <= 7, 0 <= a < b <= N-1)
Second line contains N integers which denote the given linked list.
One linked list result after the two operations.