-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPartition.java
More file actions
51 lines (30 loc) · 841 Bytes
/
Partition.java
File metadata and controls
51 lines (30 loc) · 841 Bytes
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
46
47
48
49
50
51
import java.util.List;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
public class Partition {
public static void main(String[] args) {
Integer elements[]= {15,1,6,12,-3,4,8,21,2,30,-1,9};
List<Integer> list = new LinkedList<Integer>(Arrays.asList(elements));
partitionss(list, 5);
System.out.println(list);
}
//create method
private static void partitionss (List<Integer> list, int E){
//instance of iterator
Iterator<Integer> iterat = list.iterator();
List<Integer> newList = new LinkedList<Integer>();
// remove values
while(iterat.hasNext()) {
int numbers = iterat.next();
if(numbers<= E) {
iterat.remove();
newList.add(numbers);
}else {
//System.out.println();
}
}
//adding the numbers to list
list.addAll(0, newList);
}
}