345
|
1 package alice.test.codesegment.local.bitonicsort;
|
|
2
|
|
3 import org.msgpack.annotation.Message;
|
|
4
|
|
5 @Message
|
|
6 public class DataList {
|
|
7
|
|
8 public int[] table;
|
|
9
|
|
10 public DataList(int size){
|
|
11 table = new int[size];
|
|
12 }
|
|
13
|
|
14 public DataList(int[] numbers){
|
|
15 table = numbers;
|
|
16 }
|
|
17
|
|
18 public DataList createDataList(int start, int size){
|
|
19 int[] table2 = new int[size];
|
|
20 int end = start+size;
|
|
21 for (int i=start,j=0;i<end;i++,j++){
|
|
22 table2[j] = table[i];
|
|
23 }
|
|
24 return new DataList(table2);
|
|
25 }
|
|
26
|
|
27 public void swap(int i, int j){
|
|
28 int tmp = table[i];
|
|
29 table[i] = table[j];
|
|
30 table[j] = tmp;
|
|
31 }
|
|
32
|
|
33 public void showData(){
|
|
34 for (int aTable : table) {
|
|
35 System.out.print(aTable + " ");
|
|
36 }
|
|
37 System.out.println();
|
|
38 }
|
|
39
|
|
40 public void showData(int range){
|
|
41 for(int i = 0;i<range;i++){
|
|
42 System.out.print(table[i]+ " ");
|
|
43
|
|
44 }
|
|
45 System.out.println();
|
|
46 }
|
|
47
|
|
48 public void showSize(){
|
|
49 System.out.print("size is "+this.table.length+". ");
|
|
50 }
|
|
51
|
|
52 public int getSize(){
|
|
53 return this.table.length;
|
|
54 }
|
|
55
|
|
56 public static void merge(DataList list1, DataList list2) {
|
|
57 int[] t1 = list1.table;
|
|
58 int[] t2 = list2.table;
|
|
59 int[] t0 = list1.table.clone(); // copy to avoid destroy t1
|
|
60 int i = 0, j= 0,n=0;
|
|
61 while (i< t0.length) {
|
|
62 if (n>=t1.length) { // switch to the second list
|
|
63 t1 = t2; n = 0;
|
|
64 }
|
|
65 if (j>=t2.length || t0[i] < t2[j]) {
|
|
66 t1[n] = t0[i]; // including when j reaches end of t2
|
|
67 i++; n++;
|
|
68 } else {
|
|
69 t1[n] = t2[j];
|
|
70 j++; n++;
|
|
71 }
|
|
72 }
|
|
73 }
|
|
74
|
|
75 }
|