-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPartition.java
45 lines (38 loc) · 880 Bytes
/
Partition.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.* ;
import java.io.*;
/****************************************************************
Following is the class structure of the Node class:
class Node {
int data;
Node next;
Node(int x) {
this.data = x;
this.next = null;
}
};
*****************************************************************/
public class Solution {
public static Node findPartition(Node head, int X) {
Node curr=head;
Node less_head=new Node(0);
Node great_head=new Node(0);
Node less=less_head;
Node great=great_head;
while(curr!=null){
if (curr.data<X){
less.next=curr;
less=less.next;
}
else{
great.next=curr;
great=great.next;
}
curr=curr.next;
}
less.next=great_head.next;
head=less_head.next;
great.next=null;
// Write your code here.
return head;
}
}