成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

用java代碼實現堆排序 用java代碼實現堆排序的方法

請給出java幾種排序方法

java常見的排序分為:

成都創(chuàng)新互聯從2013年創(chuàng)立,是專業(yè)互聯網技術服務公司,擁有項目成都做網站、成都網站建設、成都外貿網站建設網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元巴林右旗做網站,已為上家服務,為巴林右旗各地企業(yè)和個人服務,聯系電話:13518219792

1 插入類排序

主要就是對于一個已經有序的序列中,插入一個新的記錄。它包括:直接插入排序,折半插入排序和希爾排序

2 交換類排序

這類排序的核心就是每次比較都要“交換”,在每一趟排序都會兩兩發(fā)生一系列的“交換”排序,但是每一趟排序都會讓一個記錄排序到它的最終位置上。它包括:起泡排序,快速排序

3 選擇類排序

每一趟排序都從一系列數據中選擇一個最大或最小的記錄,將它放置到第一個或最后一個為位置交換,只有在選擇后才交換,比起交換類排序,減少了交換記錄的時間。屬于它的排序:簡單選擇排序,堆排序

4 歸并類排序

將兩個或兩個以上的有序序列合并成一個新的序列

5 基數排序

主要基于多個關鍵字排序的。

下面針對上面所述的算法,講解一些常用的java代碼寫的算法

二 插入類排序之直接插入排序

直接插入排序,一般對于已經有序的隊列排序效果好。

基本思想:每趟將一個待排序的關鍵字按照大小插入到已經排序好的位置上。

算法思路,從后往前先找到要插入的位置,如果小于則就交換,將元素向后移動,將要插入數據插入該位置即可。時間復雜度為O(n2),空間復雜度為O(1)

package sort.algorithm;

public class DirectInsertSort {

public static void main(String[] args) {

// TODO Auto-generated method stub

int data[] = { 2, 6, 10, 3, 9, 80, 1, 16, 27, 20 };

int temp, j;

for (int i = 1; i data.length; i++) {

temp = data[i];

j = i - 1;

// 每次比較都是對于已經有序的

while (j = 0 data[j] temp) {

data[j + 1] = data[j];

j--;

}

data[j + 1] = temp;

}

// 輸出排序好的數據

for (int k = 0; k data.length; k++) {

System.out.print(data[k] + " ");

}

}

}

三 插入類排序之折半插入排序(二分法排序)

條件:在一個已經有序的隊列中,插入一個新的元素

折半插入排序記錄的比較次數與初始序列無關

思想:折半插入就是首先將隊列中取最小位置low和最大位置high,然后算出中間位置mid

將中間位置mid與待插入的數據data進行比較,

如果mid大于data,則就表示插入的數據在mid的左邊,high=mid-1;

如果mid小于data,則就表示插入的數據在mid的右邊,low=mid+1

最后整體進行右移操作。

時間復雜度O(n2),空間復雜度O(1)

package sort.algorithm;

//折半插入排序

public class HalfInsertSort {

public static void main(String[] args) {

int data[] = { 2, 6, 10, 3, 9, 80, 1, 16, 27, 20 };

// 存放臨時要插入的元素數據

int temp;

int low, mid, high;

for (int i = 1; i data.length; i++) {

temp = data[i];

// 在待插入排序的序號之前進行折半插入

low = 0;

high = i - 1;

while (low = high) {

mid = (low + high) / 2;

if (temp data[mid])

high = mid - 1;

else

// low=high的時候也就是找到了要插入的位置,

// 此時進入循環(huán)中,將low加1,則就是要插入的位置了

low = mid + 1;

}

// 找到了要插入的位置,從該位置一直到插入數據的位置之間數據向后移動

for (int j = i; j = low + 1; j--)

data[j] = data[j - 1];

// low已經代表了要插入的位置了

data[low] = temp;

}

for (int k = 0; k data.length; k++) {

System.out.print(data[k] + " ");

}

}

}

四 插入類排序之希爾排序

希爾排序,也叫縮小增量排序,目的就是盡可能的減少交換次數,每一個組內最后都是有序的。

將待續(xù)按照某一種規(guī)則分為幾個子序列,不斷縮小規(guī)則,最后用一個直接插入排序合成

空間復雜度為O(1),時間復雜度為O(nlog2n)

算法先將要排序的一組數按某個增量d(n/2,n為要排序數的個數)分成若干組,每組中記錄的下標相差d.對每組中全部元素進行直接插入排序,然后再用一個較小的增量(d/2)對它進行分組,在每組中再進行直接插入排序。當增量減到1時,進行直接插入排序后,排序完成。

package sort.algorithm;

public class ShellSort {

public static void main(String[] args) {

int a[] = { 1, 54, 6, 3, 78, 34, 12, 45, 56, 100 };

double d1 = a.length;

int temp = 0;

while (true)

{

//利用這個在將組內倍數減小

//這里依次為5,3,2,1

d1 = Math.ceil(d1 / 2);

//d為增量每個分組之間索引的增量

int d = (int) d1;

//每個分組內部排序

for (int x = 0; x d; x++)

{

//組內利用直接插入排序

for (int i = x + d; i a.length; i += d) {

int j = i - d;

temp = a[i];

for (; j = 0 temp a[j]; j -= d) {

a[j + d] = a[j];

}

a[j + d] = temp;

}

}

if (d == 1)

break;

}

for (int i = 0; i a.length; i++)

System.out.print(a[i]+" ");

}

}

五 交換類排序之冒泡排序

交換類排序核心就是每次比較都要進行交換

冒泡排序:是一種交換排序

每一趟比較相鄰的元素,較若大小不同則就會發(fā)生交換,每一趟排序都能將一個元素放到它最終的位置!每一趟就進行比較。

時間復雜度O(n2),空間復雜度O(1)

package sort.algorithm;

//冒泡排序:是一種交換排序

public class BubbleSort {

// 按照遞增順序排序

public static void main(String[] args) {

// TODO Auto-generated method stub

int data[] = { 2, 6, 10, 3, 9, 80, 1, 16, 27, 20, 13, 100, 37, 16 };

int temp = 0;

// 排序的比較趟數,每一趟都會將剩余最大數放在最后面

for (int i = 0; i data.length - 1; i++) {

// 每一趟從開始進行比較,將該元素與其余的元素進行比較

for (int j = 0; j data.length - 1; j++) {

if (data[j] data[j + 1]) {

temp = data[j];

data[j] = data[j + 1];

data[j + 1] = temp;

}

}

}

for (int i = 0; i data.length; i++)

System.out.print(data[i] + " ");

}

}

java快速排序簡單代碼

.example-btn{color:#fff;background-color:#5cb85c;border-color:#4cae4c}.example-btn:hover{color:#fff;background-color:#47a447;border-color:#398439}.example-btn:active{background-image:none}div.example{width:98%;color:#000;background-color:#f6f4f0;background-color:#d0e69c;background-color:#dcecb5;background-color:#e5eecc;margin:0 0 5px 0;padding:5px;border:1px solid #d4d4d4;background-image:-webkit-linear-gradient(#fff,#e5eecc 100px);background-image:linear-gradient(#fff,#e5eecc 100px)}div.example_code{line-height:1.4em;width:98%;background-color:#fff;padding:5px;border:1px solid #d4d4d4;font-size:110%;font-family:Menlo,Monaco,Consolas,"Andale Mono","lucida console","Courier New",monospace;word-break:break-all;word-wrap:break-word}div.example_result{background-color:#fff;padding:4px;border:1px solid #d4d4d4;width:98%}div.code{width:98%;border:1px solid #d4d4d4;background-color:#f6f4f0;color:#444;padding:5px;margin:0}div.code div{font-size:110%}div.code div,div.code p,div.example_code p{font-family:"courier new"}pre{margin:15px auto;font:12px/20px Menlo,Monaco,Consolas,"Andale Mono","lucida console","Courier New",monospace;white-space:pre-wrap;word-break:break-all;word-wrap:break-word;border:1px solid #ddd;border-left-width:4px;padding:10px 15px} 排序算法是《數據結構與算法》中最基本的算法之一。排序算法可以分為內部排序和外部排序,內部排序是數據記錄在內存中進行排序,而外部排序是因排序的數據很大,一次不能容納全部的排序記錄,在排序過程中需要訪問外存。常見的內部排序算法有:插入排序、希爾排序、選擇排序、冒泡排序、歸并排序、快速排序、堆排序、基數排序等。以下是快速排序算法:

快速排序是由東尼·霍爾所發(fā)展的一種排序算法。在平均狀況下,排序 n 個項目要 Ο(nlogn) 次比較。在最壞狀況下則需要 Ο(n2) 次比較,但這種狀況并不常見。事實上,快速排序通常明顯比其他 Ο(nlogn) 算法更快,因為它的內部循環(huán)(inner loop)可以在大部分的架構上很有效率地被實現出來。

快速排序使用分治法(Divide and conquer)策略來把一個串行(list)分為兩個子串行(sub-lists)。

快速排序又是一種分而治之思想在排序算法上的典型應用。本質上來看,快速排序應該算是在冒泡排序基礎上的遞歸分治法。

快速排序的名字起的是簡單粗暴,因為一聽到這個名字你就知道它存在的意義,就是快,而且效率高!它是處理大數據最快的排序算法之一了。雖然 Worst Case 的時間復雜度達到了 O(n?),但是人家就是優(yōu)秀,在大多數情況下都比平均時間復雜度為 O(n logn) 的排序算法表現要更好,可是這是為什么呢,我也不知道。好在我的強迫癥又犯了,查了 N 多資料終于在《算法藝術與信息學競賽》上找到了滿意的答案:

快速排序的最壞運行情況是 O(n?),比如說順序數列的快排。但它的平攤期望時間是 O(nlogn),且 O(nlogn) 記號中隱含的常數因子很小,比復雜度穩(wěn)定等于 O(nlogn) 的歸并排序要小很多。所以,對絕大多數順序性較弱的隨機數列而言,快速排序總是優(yōu)于歸并排序。

1. 算法步驟

從數列中挑出一個元素,稱為 "基準"(pivot);

重新排序數列,所有元素比基準值小的擺放在基準前面,所有元素比基準值大的擺在基準的后面(相同的數可以到任一邊)。在這個分區(qū)退出之后,該基準就處于數列的中間位置。這個稱為分區(qū)(partition)操作;

遞歸地(recursive)把小于基準值元素的子數列和大于基準值元素的子數列排序;

2. 動圖演示

代碼實現 JavaScript 實例 function quickSort ( arr , left , right ) {

var len = arr. length ,

? ? partitionIndex ,

? ? left = typeof left != 'number' ? 0 : left ,

? ? right = typeof right != 'number' ? len - 1 : right ;

if ( left

java堆排序代碼

//從a[index]到a[len]除了a[index]外其它元素滿足一個堆,把a[index]調整到合適位置

//這個堆滿足父節(jié)點孩子結點,且要保證2*index能取到index的左孩子,

public static void adjustHeap(int[] a,int index,int len){

int scn=a[index];

for(int i=2*index;i=m;i*=2){

if(ima[i]a[i+1])i+=1;

if(!a[i]scn)break;

a[index]=a[i];index=i;

}

a[index]=scn;

}

//數組a從a[1]開始存放元素,如果想從a[0]開始則要調整adjustHeap代碼,以便滿足完全二叉樹

//性質,代碼未經測試

public static void heapSort(int[] a){

for(int i=(a.length-1)/2;i0;i--)

adjustHeap(a,i,a.length-1);

int tmp;

for(int i=a.length-1;i1;i--){

tmp=a[i];

a[i]=a[1];

a[1]=tmp;

adjustHeap(a,1,i-1);

}

}

寫一個簡單的JAVA排序程序

// 排序

public class Array

{

public static int[] random(int n) //產生n個隨機數,返回整型數組

{

if (n0)

{

int table[] = new int[n];

for (int i=0; itable.length; i++)

table[i] = (int)(Math.random()*100); //產生一個0~100之間的隨機數

return table; //返回一個數組

}

return null;

}

public static void print(int[] table) //輸出數組元素

{

if (table!=null)

for (int i=0; itable.length; i++)

System.out.print(" "+table[i]);

System.out.println();

}

public static void insertSort(int[] table) //直接插入排序

{ //數組是引用類型,元素值將被改變

System.out.println("直接插入排序");

for (int i=1; itable.length; i++) //n-1趟掃描

{

int temp=table[i], j; //每趟將table[i]插入到前面已排序的序列中

// System.out.print("移動");

for (j=i-1; j-1 temptable[j]; j--) //將前面較大元素向后移動

{

// System.out.print(table[j]+", ");

table[j+1] = table[j];

}

table[j+1] = temp; //temp值到達插入位置

System.out.print("第"+i+"趟: ");

print(table);

}

}

public static void shellSort(int[] table) //希爾排序

{

System.out.println("希爾排序");

for (int delta=table.length/2; delta0; delta/=2) //控制增量,增量減半,若干趟掃描

{

for (int i=delta; itable.length; i++) //一趟中若干組,每個元素在自己所屬組內進行直接插入排序

{

int temp = table[i]; //當前待插入元素

int j=i-delta; //相距delta遠

while (j=0 temptable[j]) //一組中前面較大的元素向后移動

{

table[j+delta] = table[j];

j-=delta; //繼續(xù)與前面的元素比較

}

table[j+delta] = temp; //插入元素位置

}

System.out.print("delta="+delta+" ");

print(table);

}

}

private static void swap(int[] table, int i, int j) //交換數組中下標為i、j的元素

{

if (i=0 itable.length j=0 jtable.length i!=j) //判斷i、j是否越界

{

int temp = table[j];

table[j] = table[i];

table[i] = temp;

}

}

public static void bubbleSort(int[] table) //冒泡排序

{

System.out.println("冒泡排序");

boolean exchange=true; //是否交換的標記

for (int i=1; itable.length exchange; i++) //有交換時再進行下一趟,最多n-1趟

{

exchange=false; //假定元素未交換

for (int j=0; jtable.length-i; j++) //一次比較、交換

if (table[j]table[j+1]) //反序時,交換

{

int temp = table[j];

table[j] = table[j+1];

table[j+1] = temp;

exchange=true; //有交換

}

System.out.print("第"+i+"趟: ");

print(table);

}

}

public static void quickSort(int[] table) //快速排序

{

quickSort(table, 0, table.length-1);

}

private static void quickSort(int[] table, int low, int high) //一趟快速排序,遞歸算法

{ //low、high指定序列的下界和上界

if (lowhigh) //序列有效

{

int i=low, j=high;

int vot=table[i]; //第一個值作為基準值

while (i!=j) //一趟排序

{

while (ij vot=table[j]) //從后向前尋找較小值

j--;

if (ij)

{

table[i]=table[j]; //較小元素向前移動

i++;

}

while (ij table[i]vot) //從前向后尋找較大值

i++;

if (ij)

{

table[j]=table[i]; //較大元素向后移動

j--;

}

}

table[i]=vot; //基準值的最終位置

System.out.print(low+".."+high+", vot="+vot+" ");

print(table);

quickSort(table, low, j-1); //前端子序列再排序

quickSort(table, i+1, high); //后端子序列再排序

}

}

public static void selectSort(int[] table) //直接選擇排序

{

System.out.println("直接選擇排序");

for (int i=0; itable.length-1; i++) //n-1趟排序

{ //每趟在從table[i]開始的子序列中尋找最小元素

int min=i; //設第i個數據元素最小

for (int j=i+1; jtable.length; j++) //在子序列中查找最小值

if (table[j]table[min])

min = j; //記住最小元素下標

if (min!=i) //將本趟最小元素交換到前邊

{

int temp = table[i];

table[i] = table[min];

table[min] = temp;

}

System.out.print("第"+i+"趟: ");

print(table);

}

}

private static void sift(int[] table, int low, int high) //將以low為根的子樹調整成最小堆

{ //low、high是序列下界和上界

int i=low; //子樹的根

int j=2*i+1; //j為i結點的左孩子

int temp=table[i]; //獲得第i個元素的值

while (j=high) //沿較小值孩子結點向下篩選

{

if (jhigh table[j]table[j+1]) //數組元素比較(改成為最大堆)

j++; //j為左右孩子的較小者

if (temptable[j]) //若父母結點值較大(改成為最大堆)

{

table[i]=table[j]; //孩子結點中的較小值上移

i=j; //i、j向下一層

j=2*i+1;

}

else

j=high+1; //退出循環(huán)

}

table[i]=temp; //當前子樹的原根值調整后的位置

System.out.print("sift "+low+".."+high+" ");

print(table);

}

public static void heapSort(int[] table)

{

System.out.println("堆排序");

int n=table.length;

for (int j=n/2-1; j=0; j--) //創(chuàng)建最小堆

sift(table, j, n-1);

// System.out.println("最小堆? "+isMinHeap(table));

for (int j=n-1; j0; j--) //每趟將最小值交換到后面,再調整成堆

{

int temp = table[0];

table[0] = table[j];

table[j] = temp;

sift(table, 0, j-1);

}

}

public static void mergeSort(int[] X) //歸并排序

{

System.out.println("歸并排序");

int n=1; //已排序的子序列長度,初值為1

int[] Y = new int[X.length]; //Y數組長度同X數組

do

{

mergepass(X, Y, n); //一趟歸并,將X數組中各子序列歸并到Y中

print(Y);

n*=2; //子序列長度加倍

if (nX.length)

{

mergepass(Y, X, n); //將Y數組中各子序列再歸并到X中

print(X);

n*=2;

}

} while (nX.length);

}

private static void mergepass(int[] X, int[] Y, int n) //一趟歸并

{

System.out.print("子序列長度n="+n+" ");

int i=0;

while (iX.length-2*n+1)

{

merge(X,Y,i,i+n,n);

i += 2*n;

}

if (i+nX.length)

merge(X,Y,i,i+n,n); //再一次歸并

else

for (int j=i; jX.length; j++) //將X剩余元素復制到Y中

Y[j]=X[j];

}

private static void merge(int[] X, int[] Y, int m, int r, int n) //一次歸并

{

int i=m, j=r, k=m;

while (ir jr+n jX.length) //將X中兩個相鄰子序列歸并到Y中

if (X[i]X[j]) //較小值復制到Y中

Y[k++]=X[i++];

else

Y[k++]=X[j++];

while (ir) //將前一個子序列剩余元素復制到Y中

Y[k++]=X[i++];

while (jr+n jX.length) //將后一個子序列剩余元素復制到Y中

Y[k++]=X[j++];

}

public static void main(String[] args)

{

// int[] table = {52,26,97,19,66,8,49};//Array.random(9);{49,65,13,81,76,97,38,49};////{85,12,36,24,47,30,53,91,76};//;//{4,5,8,1,2,7,3,6};// {32,26,87,72,26,17};//

int[] table = {13,27,38,49,97,76,49,81}; //最小堆

System.out.print("關鍵字序列: ");

Array.print(table);

// Array.insertSort(table);

// Array.shellSort(table);

// Array.bubbleSort(table);

// Array.quickSort(table);

// Array.selectSort(table);

// Array.heapSort(table);

// Array.mergeSort(table);

System.out.println("最小堆序列? "+Array.isMinHeap(table));

}

//第9章習題

public static boolean isMinHeap(int[] table) //判斷一個數據序列是否為最小堆

{

if (table==null)

return false;

int i = table.length/2 -1; //最深一棵子樹的根結點

while (i=0)

{

int j=2*i+1; //左孩子

if (jtable.length)

if (table[i]table[j])

return false;

else

if (j+1table.length table[i]table[j+1]) //右孩子

return false;

i--;

}

return true;

}

}

/*

程序運行結果如下:

關鍵字序列: 32 26 87 72 26 17 8 40

直接插入排序

第1趟排序: 26 32 87 72 26 17 8 40

第2趟排序: 26 32 87 72 26 17 8 40

第3趟排序: 26 32 72 87 26 17 8 40

第4趟排序: 26 26 32 72 87 17 8 40 //排序算法穩(wěn)定

第5趟排序: 17 26 26 32 72 87 8 40

第6趟排序: 8 17 26 26 32 72 87 40

第7趟排序: 8 17 26 26 32 40 72 87

關鍵字序列: 42 1 74 25 45 29 87 53

直接插入排序

第1趟排序: 1 42 74 25 45 29 87 53

第2趟排序: 1 42 74 25 45 29 87 53

第3趟排序: 1 25 42 74 45 29 87 53

第4趟排序: 1 25 42 45 74 29 87 53

第5趟排序: 1 25 29 42 45 74 87 53

第6趟排序: 1 25 29 42 45 74 87 53

第7趟排序: 1 25 29 42 45 53 74 87

關鍵字序列: 21 12 2 40 99 97 68 57

直接插入排序

第1趟排序: 12 21 2 40 99 97 68 57

第2趟排序: 2 12 21 40 99 97 68 57

第3趟排序: 2 12 21 40 99 97 68 57

第4趟排序: 2 12 21 40 99 97 68 57

第5趟排序: 2 12 21 40 97 99 68 57

第6趟排序: 2 12 21 40 68 97 99 57

第7趟排序: 2 12 21 40 57 68 97 99

關鍵字序列: 27 38 65 97 76 13 27 49 55 4

希爾排序

delta=5 13 27 49 55 4 27 38 65 97 76

delta=2 4 27 13 27 38 55 49 65 97 76

delta=1 4 13 27 27 38 49 55 65 76 97

關鍵字序列: 49 38 65 97 76 13 27 49 55 4 //嚴書

希爾排序

delta=5 13 27 49 55 4 49 38 65 97 76

delta=2 4 27 13 49 38 55 49 65 97 76 //與嚴書不同

delta=1 4 13 27 38 49 49 55 65 76 97

關鍵字序列: 65 34 25 87 12 38 56 46 14 77 92 23

希爾排序

delta=6 56 34 14 77 12 23 65 46 25 87 92 38

delta=3 56 12 14 65 34 23 77 46 25 87 92 38

delta=1 12 14 23 25 34 38 46 56 65 77 87 92

關鍵字序列: 84 12 43 62 86 7 90 91

希爾排序

delta=4 84 7 43 62 86 12 90 91

delta=2 43 7 84 12 86 62 90 91

delta=1 7 12 43 62 84 86 90 91

關鍵字序列: 32 26 87 72 26 17

冒泡排序

第1趟排序: 26 32 72 26 17 87

第2趟排序: 26 32 26 17 72 87

第3趟排序: 26 26 17 32 72 87

第4趟排序: 26 17 26 32 72 87

第5趟排序: 17 26 26 32 72 87

關鍵字序列: 1 2 3 4 5 6 7 8

冒泡排序

第1趟排序: 1 2 3 4 5 6 7 8

關鍵字序列: 1 3 2 4 5 8 6 7

冒泡排序

第1趟排序: 1 2 3 4 5 6 7 8

第2趟排序: 1 2 3 4 5 6 7 8

關鍵字序列: 4 5 8 1 2 7 3 6

冒泡排序

第1趟排序: 4 5 1 2 7 3 6 8

第2趟排序: 4 1 2 5 3 6 7 8

第3趟排序: 1 2 4 3 5 6 7 8

第4趟排序: 1 2 3 4 5 6 7 8

第5趟排序: 1 2 3 4 5 6 7 8

關鍵字序列: 38 26 97 19 66 1 5 49

0..7, vot=38 5 26 1 19 38 66 97 49

0..3, vot=5 1 5 26 19 38 66 97 49

2..3, vot=26 1 5 19 26 38 66 97 49

5..7, vot=66 1 5 19 26 38 49 66 97

關鍵字序列: 38 5 49 26 19 97 1 66

0..7, vot=38 1 5 19 26 38 97 49 66

0..3, vot=1 1 5 19 26 38 97 49 66

1..3, vot=5 1 5 19 26 38 97 49 66

2..3, vot=19 1 5 19 26 38 97 49 66

5..7, vot=97 1 5 19 26 38 66 49 97

5..6, vot=66 1 5 19 26 38 49 66 97

關鍵字序列: 49 38 65 97 76 13 27 49

0..7, vot=49 49 38 27 13 49 76 97 65

0..3, vot=49 13 38 27 49 49 76 97 65

0..2, vot=13 13 38 27 49 49 76 97 65

1..2, vot=38 13 27 38 49 49 76 97 65

5..7, vot=76 13 27 38 49 49 65 76 97

關鍵字序列: 27 38 65 97 76 13 27 49 55 4

low=0 high=9 vot=27 4 27 13 27 76 97 65 49 55 38

low=0 high=2 vot=4 4 27 13 27 76 97 65 49 55 38

low=1 high=2 vot=27 4 13 27 27 76 97 65 49 55 38

low=4 high=9 vot=76 4 13 27 27 38 55 65 49 76 97

low=4 high=7 vot=38 4 13 27 27 38 55 65 49 76 97

low=5 high=7 vot=55 4 13 27 27 38 49 55 65 76 97

關鍵字序列: 38 26 97 19 66 1 5 49

直接選擇排序

第0趟排序: 1 26 97 19 66 38 5 49

第1趟排序: 1 5 97 19 66 38 26 49

第2趟排序: 1 5 19 97 66 38 26 49

第3趟排序: 1 5 19 26 66 38 97 49

第4趟排序: 1 5 19 26 38 66 97 49

第5趟排序: 1 5 19 26 38 49 97 66

第6趟排序: 1 5 19 26 38 49 66 97

最小堆

關鍵字序列: 81 49 76 27 97 38 49 13 65

sift 3..8 81 49 76 13 97 38 49 27 65

sift 2..8 81 49 38 13 97 76 49 27 65

sift 1..8 81 13 38 27 97 76 49 49 65

sift 0..8 13 27 38 49 97 76 49 81 65

13 27 38 49 97 76 49 81 65

sift 0..7 27 49 38 65 97 76 49 81 13

sift 0..6 38 49 49 65 97 76 81 27 13

sift 0..5 49 65 49 81 97 76 38 27 13

sift 0..4 49 65 76 81 97 49 38 27 13

sift 0..3 65 81 76 97 49 49 38 27 13

sift 0..2 76 81 97 65 49 49 38 27 13

sift 0..1 81 97 76 65 49 49 38 27 13

sift 0..0 97 81 76 65 49 49 38 27 13

最大堆

關鍵字序列: 49 65 13 81 76 27 97 38 49

sift 3..8 49 65 13 81 76 27 97 38 49

sift 2..8 49 65 97 81 76 27 13 38 49

sift 1..8 49 81 97 65 76 27 13 38 49

sift 0..8 97 81 49 65 76 27 13 38 49

97 81 49 65 76 27 13 38 49

sift 0..7 81 76 49 65 49 27 13 38 97

sift 0..6 76 65 49 38 49 27 13 81 97

sift 0..5 65 49 49 38 13 27 76 81 97

sift 0..4 49 38 49 27 13 65 76 81 97

sift 0..3 49 38 13 27 49 65 76 81 97

sift 0..2 38 27 13 49 49 65 76 81 97

sift 0..1 27 13 38 49 49 65 76 81 97

sift 0..0 13 27 38 49 49 65 76 81 97

關鍵字序列: 52 26 97 19 66 8 49

歸并排序

子序列長度n=1 26 52 19 97 8 66 49

子序列長度n=2 19 26 52 97 8 49 66

子序列長度n=4 8 19 26 49 52 66 97

關鍵字序列: 13 27 38 49 97 76 49 81 65

最小堆序列? true

*/

分享名稱:用java代碼實現堆排序 用java代碼實現堆排序的方法
瀏覽地址:http://jinyejixie.com/article2/dohpsoc.html

成都網站建設公司_創(chuàng)新互聯,為您提供網站設計公司電子商務、品牌網站建設網站設計、域名注冊、小程序開發(fā)

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

網站優(yōu)化排名
简阳市| 宾阳县| 徐闻县| 二手房| 诏安县| 儋州市| 滕州市| 浦东新区| 鄂托克旗| 阜康市| 隆安县| 闽清县| 阿瓦提县| 五寨县| 平武县| 新巴尔虎右旗| 平和县| 兴仁县| 廊坊市| 蓝山县| 吉木萨尔县| 大港区| 平定县| 湖口县| 张家界市| 密云县| 曲沃县| 温州市| 莱州市| 仙游县| 桦甸市| 嘉定区| 西贡区| 水富县| 苍梧县| 宿州市| 朝阳县| 庄浪县| 开封市| 台南县| 齐河县|