第二週專案3的程式1 複雜度

2021-08-08 04:38:41 字數 1226 閱讀 8341

#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);

selectsort(x, n);

t2=time(0);

printf("用時 %d 秒!", (int)(t2-t1));

fclose(fp);

return

0;}

#include 

#include

#include

#define maxnum 100000

void quicksort(int data,int first,int

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 秒!", (int)(t2-t1));

fclose(fp);

return

0;}

實踐心得:通過上面的對比可知,不同演算法耗費時間不同,而在現實生活中選擇合適的演算法才能事半功倍。

附:專案3的程式3——漢諾塔程式

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

問題及 檔名稱 no2.cpp 完成日期 2015年9月13日 版本號 v1.0 問題描述 本專案提供兩種排序演算法,複雜度為o n2 的選擇排序selectsort,和複雜度為o nlogn 的快速排序quicksort,在main函式中加入了 對執行時間的統計。輸入描述 numbers.txt ...

第二週專案3 體驗複雜度 1

檔名稱 體驗複雜度.cpp 作 者 黃玉嬌 完成日期 2016年9月8日 版 本 號 v1.0 問題描述 排序是電腦科學中的乙個基本問題,產生了很多種適合不同情況下適 用的演算法,也一直作為演算法研究的熱點。本專案提供兩種排序演算法,復 雜度為o n 2 的選擇排序selectsort,和複雜度為o...

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

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