-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsolution.tar
More file actions
123 lines (83 loc) · 5.5 KB
/
Copy pathsolution.tar
File metadata and controls
123 lines (83 loc) · 5.5 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
src/org/blueocean/ClientRGAQ.java 000644 000765 000024 00000002004 12412365602 020277 0 ustar 00junminliu staff 000000 000000 package org.blueocean;
import java.util.ArrayList;
import java.util.List;
public class ClientRGAQ {
/*
* generic class represent each element of the square
*/
static class Node<T>{
private T data;
public Node(T obj){
this.data = obj;
}
public T getData(){
return data;
}
}
/*
* 2D array is a square
*/
public static <T> Node<T>[][] to2DArray(T[] input){
int rowNum = (int) Math.ceil(Math.sqrt(input.length));
@SuppressWarnings("unchecked")
Node<T>[][] arrays = new Node[rowNum][rowNum];
for(int i=0; i<input.length; i++){
Node<T> node = new Node<T>(input[i]);
arrays[i/rowNum][i%rowNum] = node;
}
return arrays;
}
/**
* convert 2D array to list
*
* @param input
* @return
*/
public static <T> List<T> to1DArray(Node<T>[][] input){
List<T> resultList = new ArrayList<T>();
for(int i=0; i<input.length; i++){
for(int j=0; j<input[i].length; j++)
if(input[i][j]!=null)
resultList.add(input[i][j].data);
}
return resultList;
}
}