# HG changeset patch # User Shinji KONO # Date 1364396875 -32400 # Node ID c2bf9a71005ef48946aaded74c03691673ffc12c # Parent 9fe7afd7d29202788a9b3480fc518bf11f7c8a81 single loop merge diff -r 9fe7afd7d292 -r c2bf9a71005e src/alice/test/codesegment/local/bitonicsort/DataList.java --- a/src/alice/test/codesegment/local/bitonicsort/DataList.java Wed Mar 27 21:14:59 2013 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/DataList.java Thu Mar 28 00:07:55 2013 +0900 @@ -40,28 +40,20 @@ public static void merge(DataList list1, DataList list2) { int[] t1 = list1.table; int[] t2 = list2.table; - int[] t0 = list1.table.clone(); + int[] t0 = list1.table.clone(); // copy to avoid destroy t1 int i = 0, j= 0,n=0; - while (i< t0.length && n=t2.length || t0[i] < t2[j]) { - t1[n] = t0[i]; + while (i< t0.length) { + if (n>=t1.length) { // switch to the second list + t1 = t2; n = 0; + } + if (j>=t2.length || t0[i] < t2[j]) { + t1[n] = t0[i]; // including when j reaches end of t2 i++; n++; } else { t1[n] = t2[j]; j++; n++; } } - while (i< t0.length && n=t2.length || t0[i] < t2[j]) { - t2[n-t1.length] = t0[i]; - i++; n++; - } else { - t2[n-t1.length] = t2[j]; - j++; n++; - } - } - - } }