Sort (排序)
動手玩玩看
什麼時候會排序?
在程式語言裡長什麼樣子
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int studentHeights[N] = { 161, 167, 173, 152, 180, 163, 167, 170, 182, 120 };
int main(){
cout << "排序前的同學身高為 : ";
for ( int i = 0 ; i < N ; i++ )
cout << studentHeights[i] << " ";
cout << endl;
for ( int i = 0 ; i < N ; i++ )
for ( int j = i+1 ; j < N ; j++ )
if ( studentHeights[i] < studentHeights[j] )
swap( studentHeights[i], studentHeights[j] );
cout << "排序後的同學身高為 : ";
for ( int i = 0 ; i < N ; i++ )
cout << studentHeights[i] << " ";
cout << endl;
return 0;
}
有哪些排序法
- Insertion Sort
- Selection Sort
- Bubble Sort
- Counting Sort
- Quick Sort (Advanced)
Merge Sort (Advanced)
Heap Sort (Advanced)
Radix Sort (Advanced)
時間複雜度
- 做類似事情的code, 為什麼別人0.1秒就跑完了,我的卻要1.5秒
- 檢定時出現 TLE(Time Limit Exceed),我的想法是對的,為什麼只拿60分
- 如何評估時間複雜度,知道我寫的程式大概多久會跑完