Mercurial > hg > Members > tatsuki > Alice
changeset 222:c2bf9a71005e working
single loop merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 28 Mar 2013 00:07:55 +0900 |
parents | 9fe7afd7d292 |
children | f4aaada20712 |
files | src/alice/test/codesegment/local/bitonicsort/DataList.java |
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 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<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++; - } - } - - } }