第二週專案3 體驗複雜度

2021-08-08 13:14:08 字數 1623 閱讀 6481

[html]view plain

copy

*檔名稱:123.cpp  

*作    者:張俊傑  

*完成日期:2023年9月20日  

*版 本 號:v1.0  

*  *問題描述:體驗不同演算法所執行的時間

*輸入描述:

*程式輸出:見程式執行截圖  

*/  

[csharp]view plain

copy

#include 

#include 

#include 

#define maxnum 100000

void

selectsort(

inta, 

intn)  

if(k != j)  

}  }  int

main()  

while

(fscanf(fp, 

"%d"

, &x[n])!=eof)  

n++;  

printf("資料量:%d, 開始排序...."

, n);  

t1=time(0);  

selectsort(x, n);  

t2=time(0);  

printf("用時 %d 秒!"

//快速排序

#include 

#include 

#include 

#define maxnum 100000

void

quicksort(

intdata,

intfirst,

intlast)  

}  data[first]=data[i];  

data[i]=base

;  quicksort(data,first,i-1);  

quicksort(data,i+1,last);  

}  int

main()  

while

(fscanf(fp, 

"%d"

, &x[n])!=eof)  

n++;  

printf("資料量:%d, 開始排序...."

, n);  

t1=time(0);  

quicksort(x, 0, n-1);  

t2=time(0);  

printf("用時 %d 秒!"

(第二週專案3)體驗複雜度

1 兩種排序演算法的執行時間 提供兩種排序演算法,複雜度為o n 2 的選擇排序selectsort,和複雜度為o nlogn 的快速排序quicksort,在main函式中加入了對執行時間的統計。利用乙個將近10萬條資料的檔案作為輸入資料執行程式,感受兩種演算法在執行時間上的差異。執行中需要的資料...

第二週 專案3 體驗複雜度

include include include define maxnum 100000 void selectsort int a,int n if k j int main while fscanf fp,d x n eof n printf 資料量 d,開始排序.n t1 time 0 sel...

第二週專案3 體驗複雜度

檔名稱 專案3體驗複雜度.cpp 作 者 林穎 完成日期 2015年9月11日 問題描述 排序是電腦科學中的乙個基本問題,產生了很多種適合不同情況下適用的演算法,也一直作為演算法研究的熱點。本專案提供兩種排序演算法,複雜度為o n2 的選擇排序selectsort,和複雜度為o nlogn 的快速排...