以下文章**亦風亦塵的空間http://blog.csdn.net/lschou520/archive/2008/10/29/3176422.aspx
插入排序:
package org.rut.util.algorithm.support;
import org.rut.util.algorithm.sortutil;
public
class insertsort implements sortutil.sort
}
} }
氣泡排序:
package org.rut.util.algorithm.support;
import org.rut.util.algorithm.sortutil;
public
class bubblesort implements sortutil.sort
} }
} }
選擇排序:
package org.rut.util.algorithm.support;
import org.rut.util.algorithm.sortutil;
public
class selectionsort implements sortutil.sort
} sortutil.swap(data,i,lowindex);
} }
} shell排序:
package org.rut.util.algorithm.support;
import org.rut.util.algorithm.sortutil;
public
class shellsort implements sortutil.sort
} insertsort(data,0,1);
} /**
* @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;
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;
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;
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;
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)
} }
} 堆排序:
package org.rut.util.algorithm.support;
import org.rut.util.algorithm.sortutil;
public
class heapsort implements sortutil.sort
private
static
class maxheap
} private
int size=0;
private
int queue;
public
int get()
public
void remove()
//fixdown
private
void fixdown(int k)
} 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;
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實現排序演算法
四種排序方式 1.氣泡排序 2.插入排序 3.快速排序 4.歸併排序 author zhaijian public class sorts bubblesort a insertsort a quicksort a mergesort a print a 氣泡排序 兩個迴圈,第乙個迴圈是指要排序的總...
排序演算法java實現
選擇排序類 交換排序類 歸併排序類 附工具類 直接插入排序public class insertionsorter a j tmp arrayutils.printarray a public static super anytype void sort anytype a,int left,int...
排序演算法 Java 實現
1.氣泡排序高階之路 最簡單的交換排序 每個數與之後的所有數比較 param arr public void sort int arr 正宗的氣泡排序 每次從最後開始找出最小的數放在最前面,最小的數像氣泡一樣慢慢浮出水面 param arr public void bubblesort int ar...