各種排序演算法java實現

2021-04-03 02:36:34 字數 3285 閱讀 6319

插入排序:

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

}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)

堆排序:

各種排序演算法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 ...

各種排序演算法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 ...

各種排序演算法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 ...