/**
* introduction to algorithms, second edition
* 5.3 permute-by-sorting
* @author 土豆爸爸
* */
public class permutebysorting
//根據隨機數組對目標資料進行排序
sort(array, p);
}
/**
* 根據p對array重排
* @param array 待重排陣列
* @param p 隨機數組
*/
private static void sort(int array, int p)
p[i + 1] = key;
int temp = array[j];
array[j] = array[i + 1];
array[i + 1] = temp;
}
}
}import junit.framework.testcase;
public class permutebysortingtest extends testcase ;
for (int i = 0; i < array.length; i++)
}
private void print(int array)
system.out.println();
}
}
演算法導論示例 InsertSort
introduction to algorithms,second edition 2.1 insertsort author 土豆爸爸 public class insertsort array i 1 key import junit.framework.testcase public clas...
演算法導論示例 MergeSort
introduction to algorithms,second edition 2.3 mergesort author 土豆爸爸 public class mergesort public static void merge int array,int p,int q,int r l i in...
演算法導論示例 HeapSort
introduction to algorithms,second edition 6.4 heapsort author 土豆爸爸 public class heapsort 構建max heap private void buildmaxheap 使陣列的第i個元素按max heap規則重排 p...