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
}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
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(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(lthreshold)
if((j-l)>threshold)
}//new insertsort().sort(data);
insertsort(data);
}/**
* @param data
*/private void insertsort(int data)
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++)
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)
}private void fixup(int k) }}
}sortutil:
package org.rut.util.algorithm;
import org.rut.util.algorithm.support.bubblesort;
import org.rut.util.algorithm.support.heapsort;
import org.rut.util.algorithm.support.improvedmergesort;
import org.rut.util.algorithm.support.improvedquicksort;
import org.rut.util.algorithm.support.insertsort;
import org.rut.util.algorithm.support.mergesort;
import org.rut.util.algorithm.support.quicksort;
import org.rut.util.algorithm.support.selectionsort;
import org.rut.util.algorithm.support.shellsort;
/*** @author treeroot
* @since 2006-2-2
* @version 1.0
*/public class sortutil
private static string name=;
private static sort impl=new sort;
public static string tostring(int algorithm)
public static void sort(int data, int algorithm)
public static inte***ce sort
public static void swap(int data, int i, int j)
}
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...