Partition Linked List

easy
1. You are given a linked list with N nodes.
   2. You are also given a number X.
   3. You have to write a function that partitions the list such that all nodes less than x come before nodes greater than or equal to x.
      Note: You should preserve the original relative order of the nodes in each of the two partitions.
   4. display is a utility function which displays the contents of Linked List, feel free to use it for debugging purposes.
   5. main takes input from the users and creates the Linked List. You can use display to know its contents.
   6. This is a functional problem. 
   7. You should code only the partition function. It takes as input the head of the linked list and X. It should return the head of the modified linked list.
   8. Don't change the code of Node, main and display.

Input Format

First line takes N, the number of elements in the list. Second line takes input N space separated numbers reperesenting elements of the linked list. Third line takes input X. Input is handled for you.

Output Format

partitioned linked list. Output is handled for you.

Constraints

1 <= N <= 300

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
6
1 4 3 2 5 2
3
Output
1 2 2 4 3 5
Previous
Loop Detection In A Linked List
Next
Rearrange Linked List Odd Even

Related Questions