Mercurial > hg > Database > Alice
changeset 223:f4aaada20712 working
merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 28 Mar 2013 00:08:35 +0900 |
parents | c2bf9a71005e (diff) c1ce849e6417 (current diff) |
children | 409d7679cf7b 07a85aaad8e9 |
files | |
diffstat | 1 files changed, 7 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/codesegment/local/bitonicsort/DataList.java Wed Mar 27 22:58:11 2013 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/DataList.java Thu Mar 28 00:08:35 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<t1.length){ - if (j>=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<j+t1.length) { - if (j>=t2.length || t0[i] < t2[j]) { - t2[n-t1.length] = t0[i]; - i++; n++; - } else { - t2[n-t1.length] = t2[j]; - j++; n++; - } - } - - } }