-
Notifications
You must be signed in to change notification settings - Fork 0
/
PipeTest.java
49 lines (39 loc) · 1.29 KB
/
PipeTest.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
46
47
48
49
package com.company2;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/**
* Created by Benjamin R. on 30-07-2016.
*/
public class PipeTest {
public static void main(String[] args) {
Pipe[] pipes= new Pipe[3]; // Array
pipes[0]= new Pipe(0.25, 7);
pipes[1]= new Pipe(0.15, 3);
pipes[2]= new Pipe(0.27, 1);
Arrays.sort(pipes); // Built-in sort
// for (Pipe p: pipes)
// System.out.println(p);
System.out.println();
ArrayList<Pipe> pipes2= new ArrayList<Pipe>();
pipes2.add(new Pipe(0.5, 4));
pipes2.add(new Pipe(0.4, 5));
pipes2.add(new Pipe(0.3, 8));
Collections.sort(pipes2); // Built-in sort
// for (Pipe p: pipes2)
// System.out.println(p);
getSmallestToBiggest(pipes);
}
private static void getSmallestToBiggest(Pipe[] a) {
Pipe result;
for(int j=0; j<Math.pow(2,a.length); j++){
result = a[j];
int i = j-1;
while(i > 0 && a[i].getNumberOfPipes() > result.size()){
a[i+1] = a[i];
i = i- 1;
result.add(a[i + 1]);
}System.out.println(result);
}
}
}