changeset 219:665ccc899b3b working

fix merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 27 Mar 2013 21:13:38 +0900
parents b8f72b378f18
children 9fe7afd7d292
files src/alice/test/codesegment/local/bitonicsort/DataList.java
diffstat 1 files changed, 22 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/test/codesegment/local/bitonicsort/DataList.java	Wed Mar 27 16:39:51 2013 +0900
+++ b/src/alice/test/codesegment/local/bitonicsort/DataList.java	Wed Mar 27 21:13:38 2013 +0900
@@ -40,19 +40,28 @@
 	public static void merge(DataList list1, DataList list2) {
 		int[] t1 = list1.table; 
 		int[] t2 = list2.table; 
-		int i = 0, j= 0;
-		while (i< t1.length){
-			if (t1[i] < t2[j]) {
-				i++;
-			} else {
-				int tmp = t1[i];
-				t1[i] = t2[j];
-				t2[j] = tmp;
-				j++;
-			}
-			
-		}
-		
+		int[] t0 = list1.table.clone();
+		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]; 
+                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++;
+            }
+        }       
+ 
+
 	}
 	
 }