以下的程式包含四種內部搜尋法:Bubble Sort、Selection Sort、Insertion Sort、Quick Sort
程式開始會先以亂數產生十萬個數字
( #define _mexlen 100000 )
並讓使用者選擇排序使用的搜尋法
另外
因數字過多
排序的結果沒有印出
但是可以自己把 out(copy) 前面的註解拿掉
排序時
程式會自動紀錄系統時間
在排序後顯示花掉的時間
方便大家比較各種排序法的快慢
語言:C 語言
編譯器: DevC++ 4.9.9.2
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define _maxlen 100000
void out(int* in){
 int a;
 for(a=0;a<_maxlen;a++){
  printf("%4d",in);
  if(a%19==18)
   printf("\n");
 }
}
void selectionSort(int* in){
 int a=0,b=0,min=0,tmp=0;;
 for(a=0;a<_maxlen;a++){
  for(b=a;b<_maxlen;b++){
   if(in<in)
    min = b;
  }
  tmp = in;
  in = in;
  in = tmp;
 }
}
void insertionSort(int* in)
{
 int first=0,last=_maxlen-1;
 int i,j,a;
 int temp;
 for (i = first+1; i<=last;i++){
 temp = in;
  j=i-1;
  while((j>=first) && (in > temp)){
   in = in; 
   j--;
  }
  in = temp;  
 }
}
void bubbleSort(int* in){
 int a ..
訪客只能看到部份內容,免費 加入會員 或由臉書  Google 
 可以看到全部內容