herrDeng網內搜尋
自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
你會用C的算子sizeof?
-
Python CPP heap priority queue速解L eetcode 2530. Maximal Score After Applying K Operations heap/priority queue是重要的資料結構,無論是C++的std::priority_q...
-
C++ DP動態規劃解Leetcode 937 Maximum Number of Points with Cost 有些標示medium要比標示hard的問題還要難,Leetcode 1937. Maximum Number of Points with Cost,DP動態規...
72 則留言:
#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;
}
張貼留言