view src/main/java/alice/test/codesegment/local/bitonicsort/DataList.java @ 345:8f71c3e6f11d

Change directory structure Maven standard
author sugi
date Wed, 16 Apr 2014 18:26:07 +0900
parents
children aefbe41fcf12
line wrap: on
line source

package alice.test.codesegment.local.bitonicsort;

import org.msgpack.annotation.Message;

@Message
public class DataList {

	public int[] table;
	
	public DataList(int size){
		table = new int[size];
	}
	
	public DataList(int[] numbers){
		table = numbers;
	}
	
	public DataList createDataList(int start, int size){
		int[] table2 = new int[size];
		int end = start+size;
		for (int i=start,j=0;i<end;i++,j++){
			table2[j] = table[i];
		}
		return new DataList(table2);
	}
	
	public void swap(int i, int j){
		int tmp = table[i]; 
		table[i] = table[j];
		table[j] = tmp;
	}
	
	public void showData(){
		for (int aTable : table) {
			System.out.print(aTable + " ");
		}
		System.out.println();
	}
	
	public void showData(int range){
		for(int i = 0;i<range;i++){
			System.out.print(table[i]+ " ");
			
		}
		System.out.println();
	}
	
	public void showSize(){
		System.out.print("size is "+this.table.length+". ");
	}
	
	public int getSize(){
		return this.table.length;
	}

	public static void merge(DataList list1, DataList list2) {
		int[] t1 = list1.table; 
		int[] t2 = list2.table; 
		int[] t0 = list1.table.clone(); // copy to avoid destroy t1
		int i = 0, j= 0,n=0;
        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++;
            }
        }               
	}
	
}