5種常見排序演算法的完整實現

2021-07-31 00:07:39 字數 1090 閱讀 3955

預處理指令:

#include #include #include #define n 20
1-插入排序:

void insert_sort(int aa)/*插入排序*/

}

2-選擇排序:

void select_sort(int aa)/*選擇排序*/

}}

3-氣泡排序:

void bubble_sort(int aa)/*氣泡排序*/

}

4-快速排序:

void quick_sort(int aa,int low,int high)/*快速排序(氣泡排序的全新公升級版)*/

}

呼叫排序函式進行排序:

void select_to_call(int aa,char g1)/*根據輸入的字元呼叫相應的排序函式*/

下面是入口函式:

void main()

printf("\n");

printf("input a character from i,s,b,q,l:");

scanf("%c",&g);

while(!(g=='i'||g=='s'||g=='b'||g=='q'||g=='l'))

printf("the sort results are as follows:\n");

select_to_call(aa,g);

for(i=0;iprintf("%d ",aa[i]);

printf("\n\n");

printf("input \"y\" to continue next sort,otherwise exit:");

while((h=getchar())!='\n'&&h!=eof);

t=getchar();

while((h=getchar())!='\n'&&h!=eof);

}while(t=='y');

}

7種常見排序演算法的c 實現

今天心血來潮複習了一下基本的排序演算法,實現了一下,就順便發上來咯。在 裡做了注釋了 也就不多說了,直接上 吧。order algorithm.cpp 定義控制台應用程式的入口點。author netbin include stdafx.h include iostream include incl...

八種常見排序演算法java實現

目錄 1.直接插入排序 2.希爾排序 3.簡單選擇排序 4.堆排序 5.氣泡排序 6.快速排序 7.歸併排序 8.基數排序 經常碰到這樣一類排序問題 把新的資料插入到已經排好的資料列中。將第乙個數和第二個數排序,然後構成乙個有序序列 將第三個數插入進去,構成乙個新的有序序列。對第四個數 第五個數 直...

八種常見的排序演算法

演算法 穩定性時間複雜度 計數排序 穩定o n 基數排序 穩定o n 桶排序不穩定 o n 插入排序 穩定o n 2 歸併排序 穩定o nlogn 快速排序 不穩定o nlogn 希爾排序 不穩定o n 2 堆排序不穩定 o nlogn include include using namespace...