?? a605bubl.cpp
字號:
// nuovi concetti: algoritmo di ordinamento "Bubble Sort"
#include <iostream>
using namespace std;
int main() {
const int n=400;
int i, j, sup, ultimo_scambiato, t, a[n];
srand(time(0));
for (i=0; i<n; i++) a[i]=i+1;
for (i=0; i<n; i++) {
t = a[i];
j = rand()%n;
a[i] = a[j];
a[j] = t;
}
for (i=0; i<n; i++)
cout << a[i] << (i%20 == 19 ? "\n" : " ");
cout << "\nInizio ordinamento\n";
sup = n-1;
while (sup >= 0) {
ultimo_scambiato = -1;
for (i=0; i<sup; i++)
if (a[i]>a[i+1]) {
t = a[i];
a[i] = a[i+1];
a[i+1] = t;
ultimo_scambiato = i;
}
sup = ultimo_scambiato;
}
cout << "Fine ordinamento. Premere Invio...\n";
cin.get();
for (i=0; i<n; i++)
cout << a[i] << (i%20 == 19 ? "\n" : " ");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -