herrDeng網內搜尋

自訂搜尋

Ads

2009年5月19日 星期二

產生100個亂數介於0~512, 並排序!

產生100個亂數介於0~512, 並排序!

72 則留言:

B9733165 提到...

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

B9733130 提到...

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

b9733129 提到...

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

B9733176 提到...

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

b9733129 提到...

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

B9733165 提到...

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

B9733130 提到...

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

B9733159 提到...

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

B9733176 提到...

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

b9733182 提到...

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

b9733153 提到...

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

b9733178 提到...

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

b9733140 提到...

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

b9733172 提到...

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

b9733131 提到...

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

b9733179 提到...

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

b9633029 提到...

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

b9733183 提到...

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

B9733130 提到...

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

B9733129 提到...

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

b9733149 提到...

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

b9733138 提到...

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

b9733137 提到...

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

b9733132 提到...

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

b9733142 提到...

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

b9733128 提到...

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

b9733182 提到...

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

b9733157 提到...

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

b9733147 提到...

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

b9733125 提到...

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

b9733172 提到...

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

b9733162 提到...

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

b9733173 提到...

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

b9733168 提到...

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

b9733145 提到...

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

b9733144 提到...

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

b9733123 提到...

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

B9733136 提到...

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

B9733174 提到...

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

B9733181 提到...

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

B9533185 提到...

#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
請按任意鍵繼續 . . .

B9733184 提到...

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

B9733139 提到...

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

B9733143 提到...

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

B9733134 提到...

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

B9733171 提到...

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

B9733135 提到...

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

B9733188 提到...

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

B9733151 提到...

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

B9733175 提到...

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

b9733152 提到...

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

b9533182 提到...

#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

請按任意鍵繼續 . . .

b9733148 提到...

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

b9733163 提到...

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

b9733146 提到...

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

B9733133 提到...

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

B9733161 提到...

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

b9733166 提到...

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

b9733124 提到...

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

b9733127 提到...

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

b9733126 提到...

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

b9733170 提到...

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

b9633156 提到...

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

b9633139 提到...

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

b9633173 提到...

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

b9633156 提到...

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

B9733141 提到...

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

b9733150 提到...

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

B9733156 提到...

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

B9633174 提到...

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

B9733178 提到...

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

b9433003 提到...

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

Related Posts Plugin for WordPress, Blogger...

熱門文章