這是Herr Deng桑的教學blog,主要處理作業與班導事務,另外還有數位小品。
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main() { unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); int i =rand(); for (int x=0;x<101;x++) { a[x]=rand()%513; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); unsigned endtime=clock(); cout<<"CPU time:" <<(double)(endtime-starttime)/CLK_TCK <<"sec"<<endl; system("PAUSE"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main() { unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); int i =rand(); cout<<i<<endl; for (int x=0;x<101;x++) { a[x]=rand()%513; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); unsigned endtime=clock(); cout<<"CPU time:" <<(double)(endtime-starttime)/CLK_TCK <<"sec"<<endl; system("PAUSE"); return 0;}
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl; }void bubbleSort(int a[], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main(){ unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); int i =rand(); for (int i=0;i<101;i++) { a[i]=rand()%513; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); unsigned endtime=clock(); cout<<"CPU time:" <<(double)(endtime-starttime)/CLK_TCK <<"sec"<<endl; system("PAUSE"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main() { unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); int i =rand(); cout<<i<<endl; for (int x=0;x<101;x++) { a[x]=rand()%513; cout<<"a["<<x<<"]="<<a[x]<<endl; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); unsigned endtime=clock(); cout<<"CPU time:" <<(double)(endtime-starttime)/CLK_TCK <<"sec"<<endl; system("PAUSE"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main() { unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); int i =rand(); for (int x=0;x<101;x++) { a[x]=rand()%513; cout<<"a["<<x<<"]="<<a[x]<<endl; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); unsigned endtime=clock(); cout<<"CPU time:" <<(double)(endtime-starttime)/CLK_TCK <<"sec"<<endl; system("PAUSE"); return 0;}
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl; }void bubbleSort(int a[], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main(){ unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); int i =rand(); for (int i=0;i<101;i++) { a[i]=rand()%513; cout<<"a["<<i<<"]="<<a[i]<<endl; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); unsigned endtime=clock(); cout<<"CPU time:" <<(double)(endtime-starttime)/CLK_TCK <<"sec"<<endl; system("PAUSE"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a[], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl; output(a,count); }; }int main(){ unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); for (int i=0;i<101;i++) { a[i]=rand()%513; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); system("PAUSE"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a[], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main(){ unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); for (int i=1;i<101;i++) { a[i]=rand()%513; cout<<"a["<<i<<"]="<<a[i]<<endl; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); system("PAUSE"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void random100(int a[], int len){ srand((unsigned)time(NULL)); for (int x=0;x<len;x++) { a[x]=rand()%513; cout<<"a["<<x<<"]="<<a[x]<<endl; }}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main(){ int a[100]; random100(a,100); bubbleSort(a,100); cout<<"\nFinal result:\n"; output(a,100); system("PAUSE"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main() { unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); for (int x=0;x<101;x++) { a[x]=rand()%513; cout<<"a["<<x<<"]="<<a[x]<<endl; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); unsigned endtime=clock(); cout<<"CPU time:" <<(double)(endtime-starttime)/CLK_TCK <<"sec"<<endl; system("PAUSE"); return 0;}
#include <stdio.h>#include <iostream>using namespace std;#include <stdlib.h>#include <time.h>void random100(int a[],int len){ srand((unsigned)time(NULL)); printf("排序前\n"); for (int x=0;x<len ;x++) { a[x]=rand()%512; printf("%d\t",a[x]); }}void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) { if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); } }} int main(){ int a[100]; random100(a,100); bubbleSort(a,100); cout<<"排序後"<<"\t"<<endl; output(a,100); system ("pause"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){for (int i=0; i<count; i++)cout<<a[i]<<'\t';cout<<endl;}void bubbleSort(int a[], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main(){ unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); for (int i=1;i<101;i++) { a[i]=rand()%513; cout<<"a["<<i<<"]="<<a[i]<<endl; } bubbleSort(a, 100); cout<<"\nFinal result:\n";output(a,100); system("PAUSE"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a[], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main(){ unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); for (int x=0;x<100;x++) { a[x]=rand()%513; cout<<"a["<<x<<"]="<<a[x]<<endl; } bubbleSort(a, 100); cout<<"\nFinal result:\n"; output(a,100); system("PAUSE"); return 0;}
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { int i,j,temp; for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }int main(){ unsigned starttime=clock(); int a[100]; srand((unsigned)time(NULL)); int i =rand(); cout<<i<<endl; for (int x=0;x<100;x++) { a[x]=rand()%513; cout<<"a["<<x<<"]="<<a[x]<<endl; } bubbleSort(a,100); cout<<"\nFinal result:\n"; output(a,100); system("pause"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int data[], int count){ for (int i=0; i<count; i++) cout<<data[i]<<'\t'; cout<<endl;}void bubbleSort(int data [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( data[i+1] < data[i] ) swap(data[i],data[i+1]); }; }void random100(int data[], int len){ srand((unsigned)time(NULL)); for (int x=0;x<len;x++) { data[x]=rand()%513; printf("%d\t",data[x]); }}int main(){ int data[100]; random100(data,100); bubbleSort(data, 100); printf("排序後:\n"); output(data,100); system("Pause"); return 0; }
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }void random100(int a[], int len){ srand((unsigned)time(NULL)); for (int x=0;x<len;x++) { a[x]=rand()%513; cout<<"a["<<x<<"]="<<a[x]<<endl; }}int main(){ int a[100]; random100(a,100); bubbleSort(a, 100); cout<<"\nFinal result:\n" ; output(a,100); system("Pause"); return 0; }
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int data[], int count){ for (int i=0; i<count; i++) cout<<data[i]<<'\t'; cout<<endl;}void bubbleSort(int data [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( data[i+1] < data[i] ) swap(data[i],data[i+1]); } }void random100(int data[], int len){ srand((unsigned)time(NULL)); for (int x=0;x<len;x++) { data[x]=rand()%513; printf("%d\t",data[x]); }}int main(){ int data[100]; random100(data,100); bubbleSort(data, 100); printf("排序後:\n"); output(data,100); system("Pause"); return 0; }425 320 74 289 305 507 428 483 214 99213 235 170 379 11 303 473 116 427 337309 268 388 129 492 488 126 10 434 189212 416 189 172 393 284 146 131 192 40149 366 67 218 324 179 32 192 311 207319 177 182 253 383 409 247 408 144 212437 465 80 406 416 32 407 46 281 26510 208 318 48 478 330 153 324 204 384383 407 8 45 428 379 411 501 308 126364 503 321 398 131 143 452 305 428 420排序後:8 10 10 11 32 32 45 46 48 4967 74 80 99 116 126 126 129 131 131143 144 146 153 170 172 177 179 182 189189 192 192 204 207 208 212 212 213 214218 235 247 253 265 268 281 284 289 303305 305 308 309 311 318 319 320 321 324324 330 337 364 366 379 379 383 383 384388 393 398 401 406 407 407 408 409 411416 416 420 425 427 428 428 428 434 437452 465 473 478 483 488 492 501 503 507請按任意鍵繼續 . . .
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int data[], int count){ for (int i=0; i<count; i++) cout<<data[i]<<'\t'; cout<<endl;}void bubbleSort(int data [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( data[i+1] < data[i] ) swap(data[i],data[i+1]); }; }void random100(int data[], int len){ srand((unsigned)time(NULL)); cout<<"排序前:"<<endl ; for (int x=0;x<len;x++) { data[x]=rand()%513; cout<<data[x]<<"\t"; }}int main(){ int data[100]; random100(data,100); bubbleSort(data, 100); cout<<"排序後:"<<endl ; output(data,100); system("Pause"); return 0; }
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]);// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;// output(a,count); }; }void random100(int a[], int len){ srand((unsigned)time(NULL)); printf("排序前:\n"); for (int x=0;x<len;x++) { a[x]=rand()%513;// cout<<a[x]<<endl; printf("%d\t",a[x]); }}int main(){ int a[100]; random100(a,100); bubbleSort(a, 100); printf("排序後:\n"); output(a,100); system("Pause"); return 0; }
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int data[], int count){ for (int i=0; i<count; i++) cout<<data[i]<<'\t'; cout<<endl;}void random100(int data[],int len){ srand((unsigned)time(NULL)); printf("排序前:\n"); for (int x=0;x<len;x++) { data[x]=rand()%513; printf("%d\t",data[x]); }}void bubbleSort(int data [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( data[i+1] < data[i] ) swap(data[i],data[i+1]);// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;// output(data,count); }; }int main(){ int data[100]; random100(data,100); bubbleSort(data,100); printf("排序後:\n"); output(data,100); system("pause"); return 0;}
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int data[], int count){ for (int i=0; i<count; i++) cout<<data[i]<<'\t'; cout<<endl;}void bubbleSort(int data [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( data[i+1] < data[i] ) swap(data[i],data[i+1]); // cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;// output(data,count); }; }void random100(int a[], int len){ srand((unsigned)time(NULL)); for (int x=0;x<len;x++) { a[x]=rand()%513; cout<<"a["<<x<<"]="<<a[x]<<endl; }} int main(){ int a[100]; random100(a,100); bubbleSort (a,100); cout<<"nFinal result:\n"<<endl; output(a,100); system("Pause"); return 0; }
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]);// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;// output(a,count); }; }void random100(int a[], int len){ srand((unsigned)time(NULL)); printf("排序前:\n"); for (int x=0;x<len;x++) { a[x]=rand()%513; // cout<<a[x]<<endl; printf("%d\t",a[x]); }}int main(){ int a[100]; random100(a,100); bubbleSort(a, 100); printf("排序後:\n"); output(a,100); system("Pause"); return 0; }
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]);// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;// output(a,count); }; }void random100(int a[], int len){ srand((unsigned)time(NULL)); printf("排序前:\n"); for (int x=0;x<len;x++) { a[x]=rand()%513; printf("%d\t",a[x]); }}int main(){ int a[100]; random100(a,100); bubbleSort(a, 100); printf("\n排序前:\n"); output(a,100); system("Pause"); return 0; }
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]);// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;// output(a,count); }; }void random100(int a[], int len){ srand((unsigned)time(NULL)); printf("排序前:\n"); for (int x=0;x<len;x++) { a[x]=rand()%513; printf("%d\t",a[x]); }}int main(){ int a[100]; random100(a,100); bubbleSort(a, 100); printf("排序前:\n"); output(a,100); system("Pause"); return 0;
#include <iostream>#include <cstdlib>#include <ctime>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int data[], int count){ for (int i=0; i<count; i++) cout<<data[i]<<'\t'; cout<<endl;}void bubbleSort(int data [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( data[i+1] < data[i] ) swap(data[i],data[i+1]); }; }void random100(int data[], int len){ srand((unsigned)time(NULL)); for (int x=0;x<len;x++) { data[x]=rand()%513; printf("%d\t",data[x]); }}int main(){ int data[100]; random100(data,100); bubbleSort(data, 100); printf("排序後:\n"); output(data,100); system("Pause"); return 0; }268 436 70 85 191 32 419 52 359 35307 216 41 16 269 91 382 390 495 238183 202 227 288 368 186 362 351 250 506232 32 495 123 55 230 179 32 151 358102 369 288 496 446 191 489 163 317 113401 471 95 121 161 240 161 390 156 94486 239 267 56 320 480 344 347 287 15120 36 6 67 140 21 177 101 34 251254 180 8 300 318 279 165 377 199 337443 291 426 101 10 356 355 490 56 373排序後:6 8 10 15 16 21 32 32 32 3435 36 41 52 55 56 56 67 70 8591 94 95 101 101 102 113 120 121 123140 151 156 161 161 163 165 177 179 180183 186 191 191 199 202 216 227 230 232238 239 240 250 251 254 267 268 269 279287 288 288 291 300 307 317 318 320 337344 347 351 355 356 358 359 362 368 369373 377 382 390 390 401 419 426 436 443446 471 480 486 489 490 495 495 496 506請按任意鍵繼續 . . .
#include <stdio.h>#include <stdlib.h>#include <time.h>void random100(int a[],int len){ srand((unsigned)time(NULL)); printf("排序前\n"); for (int x=0;x<len ;x++) { a[x]=rand()%513; printf("%d\t",a[x]); } }void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) { if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); } }} int main(){ int a[101]; random100(a,101); bubbleSort(a,101); printf("排序後 %d\t",a[x]); system ("pause"); return 0;}
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }void random100(int a[], int len){ srand((unsigned)time(NULL)); for (int x=0;x<len;x++) { a[x]=rand()%512+1; cout<<"a["<<x<<"]="<<a[x]<<endl; }}int main(){ int a[100]; random100(a,100); bubbleSort(a, 100); cout<<"\nFinal result:\n" ; output(a,100); system("Pause"); return 0; }
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]);// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;// output(a,count); }; }void random100(int a[], int len){ srand((unsigned)time(NULL)); cout<<"排序前:"<<endl; for (int x=0;x<len;x++) { a[x]=rand()%513;// cout<<a[x]<<endl; cout<<a[x]<<"\t"; }}int main(){ int a[100]; random100(a,100); bubbleSort(a, 100); cout<<"排序後:"<<endl; output(a,100); system("Pause"); return 0; }
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){ for (int i=0; i<count; i++) cout<<a[i]<<'\t'; cout<<endl;}void bubbleSort(int a [], int count) { for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ ) if ( a[i+1] < a[i] ) swap(a[i],a[i+1]); }; }void random100(int a[], int len){ srand((unsigned)time(NULL)); printf("排序前:\n"); for (int x=0;x<len;x++) { a[x]=rand()%513; printf("%d\t",a[x]); }}int main(){ int a[100]; random100(a,100); bubbleSort(a, 100); printf("排序後:\n"); output(a,100); system("Pause"); return 0; }
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}void output(int a[], int count){for (int i=0; i<count; i++)cout<<a[i]<<'\t';cout<<endl;}void bubbleSort(int a [], int count) {for ( int j = count; j >0 ; j-- ) { for ( int i = 0; i < j-1; i++ )if ( a[i+1] < a[i] ) swap(a[i],a[i+1]);}; }void random100(int a[], int len){srand((unsigned)time(NULL));for (int x=0;x<len;x++){a[x]=rand()%513;cout<<"a["<<x<<"]="<<a[x]<<endl;}}int main(){int a[100];random100(a,100);bubbleSort(a, 100); cout<<"\nFinal result:\n" ; output(a,100);system("Pause");return 0; }
HTML 編輯器
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
for (int i=0;i<101;i++)
{
a[i]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
for (int i=0;i<101;i++)
{
a[i]=rand()%513;
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
output(a,count);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=0;i<101;i++)
{
a[i]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
output(a,count);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=0;i<101;i++)
{
a[i]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
output(a,count);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=0;i<101;i++)
{
a[i]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=1;i<101;i++)
{
a[i]=rand()%513;
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
output(a,count);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=0;i<101;i++)
{
a[i]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a,100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
output(a,count);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=0;i<101;i++)
{
a[i]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a,100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a,100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <stdio.h>
回覆刪除#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
void random100(int a[],int len)
{
srand((unsigned)time(NULL));
printf("排序前\n");
for (int x=0;x<len ;x++)
{
a[x]=rand()%512;
printf("%d\t",a[x]);
}
}
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count)
{
for ( int j = count; j >0 ; j-- )
{
for ( int i = 0; i < j-1; i++ )
{
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
}
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a,100);
cout<<"排序後"<<"\t"<<endl;
output(a,100);
system ("pause");
return 0;
}
#include <stdio.h>
回覆刪除#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
void random100(int a[],int len)
{
srand((unsigned)time(NULL));
printf("排序前\n");
for (int x=0;x<len ;x++)
{
a[x]=rand()%512;
printf("%d\t",a[x]);
}
}
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count)
{
for ( int j = count; j >0 ; j-- )
{
for ( int i = 0; i < j-1; i++ )
{
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
}
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a,100);
cout<<"排序後"<<"\t"<<endl;
output(a,100);
system ("pause");
return 0;
}
#include <stdio.h>
回覆刪除#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
void random100(int a[],int len)
{
srand((unsigned)time(NULL));
printf("排序前\n");
for (int x=0;x<len ;x++)
{
a[x]=rand()%512;
printf("%d\t",a[x]);
}
}
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count)
{
for ( int j = count; j >0 ; j-- )
{
for ( int i = 0; i < j-1; i++ )
{
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
}
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a,100);
cout<<"排序後"<<"\t"<<endl;
output(a,100);
system ("pause");
return 0;
}
#include <stdio.h>
回覆刪除#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
void random100(int a[],int len)
{
srand((unsigned)time(NULL));
printf("排序前\n");
for (int x=0;x<len ;x++)
{
a[x]=rand()%512;
printf("%d\t",a[x]);
}
}
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count)
{
for ( int j = count; j >0 ; j-- )
{
for ( int i = 0; i < j-1; i++ )
{
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
}
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a,100);
cout<<"排序後"<<"\t"<<endl;
output(a,100);
system ("pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=1;i<101;i++)
{
a[i]=rand()%513;
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=1;i<101;i++)
{
a[i]=rand()%513;
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=1;i<101;i++)
{
a[i]=rand()%513;
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=1;i<101;i++)
{
a[i]=rand()%513;
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <stdio.h>
回覆刪除#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
void random100(int a[],int len)
{
srand((unsigned)time(NULL));
printf("排序前\n");
for (int x=0;x<len ;x++)
{
a[x]=rand()%512;
printf("%d\t",a[x]);
}
}
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count)
{
for ( int j = count; j >0 ; j-- )
{
for ( int i = 0; i < j-1; i++ )
{
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
}
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a,100);
cout<<"排序後"<<"\t"<<endl;
output(a,100);
system ("pause");
return 0;
}
#include <stdio.h>
回覆刪除#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
void random100(int a[],int len)
{
srand((unsigned)time(NULL));
printf("排序前\n");
for (int x=0;x<len ;x++)
{
a[x]=rand()%512;
printf("%d\t",a[x]);
}
}
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count)
{
for ( int j = count; j >0 ; j-- )
{
for ( int i = 0; i < j-1; i++ )
{
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
}
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a,100);
cout<<"排序後"<<"\t"<<endl;
output(a,100);
system ("pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=1;i<101;i++)
{
a[i]=rand()%513;
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int i=1;i<101;i++)
{
a[i]=rand()%513;
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a[], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main()
{
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
for (int x=0;x<100;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
int i,j,temp;
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main(){
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<100;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a,100);
cout<<"\nFinal result:\n";
output(a,100);
system("pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
cout<<"\nFinal result:\n" ;
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
}
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
425 320 74 289 305 507 428 483 214 99
213 235 170 379 11 303 473 116 427 337
309 268 388 129 492 488 126 10 434 189
212 416 189 172 393 284 146 131 192 401
49 366 67 218 324 179 32 192 311 207
319 177 182 253 383 409 247 408 144 212
437 465 80 406 416 32 407 46 281 265
10 208 318 48 478 330 153 324 204 384
383 407 8 45 428 379 411 501 308 126
364 503 321 398 131 143 452 305 428 420
排序後:
8 10 10 11 32 32 45 46 48 49
67 74 80 99 116 126 126 129 131 131
143 144 146 153 170 172 177 179 182 189
189 192 192 204 207 208 212 212 213 214
218 235 247 253 265 268 281 284 289 303
305 305 308 309 311 318 319 320 321 324
324 330 337 364 366 379 379 383 383 384
388 393 398 401 406 407 407 408 409 411
416 416 420 425 427 428 428 428 434 437
452 465 473 478 483 488 492 501 503 507
請按任意鍵繼續 . . .
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
cout<<"排序前:"<<endl ;
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
cout<<data[x]<<"\t";
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
cout<<"排序後:"<<endl ;
output(data,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(a,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
// cout<<a[x]<<endl;
printf("%d\t",a[x]);
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
printf("排序後:\n");
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void random100(int data[],int len){
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(data,count);
};
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data,100);
printf("排序後:\n");
output(data,100);
system("pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(data,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort (a,100);
cout<<"nFinal result:\n"<<endl;
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(a,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
// cout<<a[x]<<endl;
printf("%d\t",a[x]);
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
printf("排序後:\n");
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(a,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
printf("%d\t",a[x]);
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
printf("\n排序前:\n");
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(a,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
printf("%d\t",a[x]);
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
printf("排序前:\n");
output(a,100);
system("Pause");
return 0;
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int data[], int count){
for (int i=0; i<count; i++)
cout<<data[i]<<'\t';
cout<<endl;
}
void bubbleSort(int data [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
void random100(int data[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
data[x]=rand()%513;
printf("%d\t",data[x]);
}
}
int main()
{
int data[100];
random100(data,100);
bubbleSort(data, 100);
printf("排序後:\n");
output(data,100);
system("Pause");
return 0;
}
268 436 70 85 191 32 419 52 359 35
307 216 41 16 269 91 382 390 495 238
183 202 227 288 368 186 362 351 250 506
232 32 495 123 55 230 179 32 151 358
102 369 288 496 446 191 489 163 317 113
401 471 95 121 161 240 161 390 156 94
486 239 267 56 320 480 344 347 287 15
120 36 6 67 140 21 177 101 34 251
254 180 8 300 318 279 165 377 199 337
443 291 426 101 10 356 355 490 56 373
排序後:
6 8 10 15 16 21 32 32 32 34
35 36 41 52 55 56 56 67 70 85
91 94 95 101 101 102 113 120 121 123
140 151 156 161 161 163 165 177 179 180
183 186 191 191 199 202 216 227 230 232
238 239 240 250 251 254 267 268 269 279
287 288 288 291 300 307 317 318 320 337
344 347 351 355 356 358 359 362 368 369
373 377 382 390 390 401 419 426 436 443
446 471 480 486 489 490 495 495 496 506
請按任意鍵繼續 . . .
#include <stdio.h>
回覆刪除#include <stdlib.h>
#include <time.h>
void random100(int a[],int len)
{
srand((unsigned)time(NULL));
printf("排序前\n");
for (int x=0;x<len ;x++)
{
a[x]=rand()%513;
printf("%d\t",a[x]);
}
}
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void bubbleSort(int a [], int count)
{
for ( int j = count; j >0 ; j-- )
{
for ( int i = 0; i < j-1; i++ )
{
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
}
}
}
int main()
{
int a[101];
random100(a,101);
bubbleSort(a,101);
printf("排序後 %d\t",a[x]);
system ("pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%512+1;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
cout<<"\nFinal result:\n" ;
output(a,100);
system("Pause");
return 0;
}
#include <stdio.h>
回覆刪除#include <stdlib.h>
#include <time.h>
void random100(int a[],int len)
{
srand((unsigned)time(NULL));
printf("排序前\n");
for (int x=0;x<len ;x++)
{
a[x]=rand()%513;
printf("%d\t",a[x]);
}
}
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void bubbleSort(int a [], int count)
{
for ( int j = count; j >0 ; j-- )
{
for ( int i = 0; i < j-1; i++ )
{
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
}
}
}
int main()
{
int a[101];
random100(a,101);
bubbleSort(a,101);
printf("排序後 %d\t",a[x]);
system ("pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(a,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
cout<<"排序前:"<<endl;
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
// cout<<a[x]<<endl;
cout<<a[x]<<"\t";
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
cout<<"排序後:"<<endl;
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
int i,j,temp;
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main(){
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<100;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a,100);
cout<<"\nFinal result:\n";
output(a,100);
system("pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
printf("%d\t",a[x]);
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
printf("排序後:\n");
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(a,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
// cout<<a[x]<<endl;
printf("%d\t",a[x]);
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
printf("排序後:\n");
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(a,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
// cout<<a[x]<<endl;
printf("%d\t",a[x]);
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
printf("排序後:\n");
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
int i,j,temp;
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main(){
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<100;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a,100);
cout<<"\nFinal result:\n";
output(a,100);
system("pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
int i,j,temp;
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main(){
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<100;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a,100);
cout<<"\nFinal result:\n";
output(a,100);
system("pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
cout<<"\nFinal result:\n" ;
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
cout<<"\nFinal result:\n" ;
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
cout<<"\nFinal result:\n" ;
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
cout<<"\nFinal result:\n" ;
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(a,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
// cout<<a[x]<<endl;
printf("%d\t",a[x]);
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
printf("排序後:\n");
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
cout<<"\nFinal result:\n" ;
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
// cout<<'\n'<<count-j+1<<" bubble(s) up->"<<endl;
// output(a,count);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
printf("排序前:\n");
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
// cout<<a[x]<<endl;
printf("%d\t",a[x]);
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
printf("排序後:\n");
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <ctime>
#include <cstdlib>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
void random100(int a[], int len)
{
srand((unsigned)time(NULL));
for (int x=0;x<len;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
}
int main()
{
int a[100];
random100(a,100);
bubbleSort(a, 100);
cout<<"\nFinal result:\n" ;
output(a,100);
system("Pause");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
cout<<"a["<<x<<"]="<<a[x]<<endl;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}
#include <iostream>
回覆刪除#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& X,int& Y){int temp=X;X=Y;Y=temp;}
void output(int a[], int count){
for (int i=0; i<count; i++)
cout<<a[i]<<'\t';
cout<<endl;
}
void bubbleSort(int a [], int count) {
for ( int j = count; j >0 ; j-- ) {
for ( int i = 0; i < j-1; i++ )
if ( a[i+1] < a[i] )
swap(a[i],a[i+1]);
};
}
int main() {
unsigned starttime=clock();
int a[100];
srand((unsigned)time(NULL));
int i =rand();
cout<<i<<endl;
for (int x=0;x<101;x++)
{
a[x]=rand()%513;
}
bubbleSort(a, 100);
cout<<"\nFinal result:\n";
output(a,100);
unsigned endtime=clock();
cout<<"CPU time:"
<<(double)(endtime-starttime)/CLK_TCK
<<"sec"<<endl;
system("PAUSE");
return 0;
}