排序演算法Java實現

2021-08-29 10:19:01 字數 1496 閱讀 4321

個人部落格:小景哥哥

} }//2.希爾排序

public static void shellsort(int a)

a[j] = t;

}} }

//3.簡單選擇排序

//在要排序的一組數中,選出最小(或者最大)的乙個數與第1個位置的數交換;然後在剩下的數當中再找最小(或者最大)的與第2個位置的數交換,依次類推,直到第n-1個元素(倒數第二個數)和第n個元素(最後乙個數)比較為止。

public static void selectsort(int a)

}int t = a[i];

a[i] = a[min];

a[min] = t;

} }//4.堆排序

public static void heapsort(int a)

} public static void buildmaxheap(int a)

} public static void percdown(int a, int i, int n)

a[i] = tmp;

} public static void swap(inta, int i, int j)

//5.氣泡排序

public static void bubblesort(int a)

}} }

//6.快速排序

public static void quicksort(int a)

public static void quicksort(int a, int l, int r)

} public static int partion(int a, int l, int r)

return l; }

//7.歸併排序

public static void mergesort(int a)

public static void mergesort(int a, int tmparray, int left, int right)

} public static void merge(int a, int tmparray, int leftpos, int rightpos, int rightend)

while(leftpos <= leftend)

tmparray[tmppos++] = a[leftpos++];

while(rightpos <= rightend)

tmparray[tmppos++] = a[rightpos++];

for(int i = 0; i < numelements; i++, rightend--)

}

排序演算法java實現

以下文章 亦風亦塵的空間http blog.csdn.net lschou520 archive 2008 10 29 3176422.aspx 插入排序 package org.rut.util.algorithm.support import org.rut.util.algorithm.sor...

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...