package org.rut.util.algorithm.support; import org.rut.util.algorithm.sortutil;/** * @author treeroot * @since 2006-2-2 * @version 1.0 */public class insertsort implements sortutil.sort } } }氣泡排序:
package org.rut.util.algorithm.support; import org.rut.util.algorithm.sortutil; /** * @author treeroot * @since 2006-2-2 * @version 1.0 */public class bubblesort implements sortutil.sort } } } 選擇排序:
package org.rut.util.algorithm.support; import org.rut.util.algorithm.sortutil; /** * @author treeroot * @since 2006-2-2 * @version 1.0 */public class selectionsort implements sortutil.sort
sortutil.swap(data,i,lowindex); } } } shell排序: package org.rut.util.algorithm.support; import org.rut.util.algorithm.sortutil; /** * @author treeroot * @since 2006-2-2 * @version 1.0 */public class shellsort implements sortutil.sort /** * @param data * @param j * @param i */
private void insertsort(int data, int start, int inc) } } }
快速排序:
package org.rut.util.algorithm.support; import org.rut.util.algorithm.sortutil; /** * @author treeroot * @since 2006-2-2 * @version 1.0 */public class quicksort implements sortutil.sort
private void quicksort(int data,int i,int j)
/** * @param data * @param i * @param j * @return */
private int partition(int data, int l, int r,int pivot) while(lsortutil.swap(data,l,r);
return l; } }
改進後的快速排序: package org.rut.util.algorithm.support; import org.rut.util.algorithm.sortutil; /** * @author treeroot * @since 2006-2-2 * @version 1.0 */public class improvedquicksort implements sortutil.sort while(lsortutil.swap(data,l,r);
sortutil.swap(data,l,j);
if((l-i)>threshold)
if((j-l)>threshold) } //new insertsort().sort(data); insertsort(data); } /** * @param data */ private void insertsort(int data) } } }
歸併排序: package org.rut.util.algorithm.support; import org.rut.util.algorithm.sortutil; /** * @author treeroot * @since 2006-2-2 * @version 1.0 */public class mergesort implements sortutil.sort
private void mergesort(int data,int temp,int l,int r)
int i1=l;
int i2=mid+1;
for(int cur=l;cur<=r;cur++) } }
改進後的歸併排序: package org.rut.util.algorithm.support; import org.rut.util.algorithm.sortutil; /** * @author treeroot * @since 2006-2-2 * @version 1.0 */public class improvedmergesort implements sortutil.sort
private void mergesort(int data, int temp, int l, int r)
for (j = 1; j <= r - mid; j++)
int a = temp[l];
int b = temp[r];
for (i = l, j = r, k = l; k <= r; k++) else } } /** * @param data * @param l * @param i */ private void insertsort(int data, int start, int len) } } }
java各種排序方法
package org.rut.util.algorithm.support import org.rut.util.algorithm.sortutil author treeroot since 2006 2 2 version 1.0 public class insertsort imple...
java各種排序方法彙總
2.選擇排序 3.插入排序 4.歸併排序 5.快速排序 public class demoarr1 int temp for int i 0 i arr.length 1 i 迴圈遍歷輸出 for int a arr public class demoarr11 scanner superman n...
各種排序方法
前一陣子為了準備暑期實習筆試 面試,把維基上查到的常用的排序演算法全寫了一遍。基本是按照演算法導論和維基上面的思路寫的,有些演算法的細節可能和一些書上有出入,但是思想是一樣的。cpp檔案在最後,如下 include include include include includeusing names...