利用srand(), rand()產生值為0~9999的int亂數存入陣列a[100],
利用 bubblesort排序a!
herrDeng網內搜尋
自訂搜尋
Ads
2010年5月25日 星期二
訂閱:
張貼留言 (Atom)
熱門文章
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
python pandas對黃金、外匯匯率的爬蟲練習,並使用matplotlib.pyplot的函數plot, scatter做資料視覺化處理,採用numpy的統計函數,分析黃金價格波動與歐元走勢的關聯。
-
Python C C++ 2 pointer速解Leetcode 2337 Move Pieces to Obtain a String 多日Leetcode的問題都可用2-pointer法來解,今日2337. Move Pieces to Obtain a String也不例...
-
你會用C的算子sizeof?
44 則留言:
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x,int &y){int t=x;x=y;y=t;}
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]);
};
}
int main() {
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
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)
{
int temp;
for ( int j = count-1; j >0 ; j-- )
{
for ( int i = 0; i < j; i++ )
if ( data[i+1] < data[i] )
{
temp=data[i+1];
data[i+1]=data[i];
data[i]=temp;
}
}
}
int main(){
int data[100];
srand((unsigned)time(NULL));
int i=rand();
for(int x=0;x<100;x++)
{
data[x]=rand()%10000;
}
cout<<"排序前\n";
output(data,100);
bubbleSort(data, 100);
cout<<"排序後\n";
output(data,100);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x,int &y){int t=x;x=y;y=t;}
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]);
}
}
int main()
{
int data[N];
srand((unsigned)time(NULL));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%9999;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成\n";
output(data,N);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
system("pause");
return 0;
}
#define N 100
#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]);
};
}
int main (){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序之前_\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成_\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
system("pause");
return 0;
}
#define N 100
#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-1; j >=0 ; j-- )
{
for(int i=0;i<j;i++)
if(data[i+1]<data[i])
swap(data[i],data[i+1]);
};
}
int main(){int data[N];
srand ((unsigned)time(NULL));
cout<<"排序前"<<endl;
for (int x=0;x<N;x++)
{
data[x]=rand()%10000;
cout<<"data["<<x<<"]="<<data[x]<<endl;
}
bubbleSort(data, N);
cout<<"排序完成"<<endl;
output(data, N);
system ("pause");
return 0;
}
#define N 100
#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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("Pause");
return 0;
}
<DIV id=yiv1671782922>#define N 100<BR>#include <iostream><BR>#include <cstdlib><BR>#include <ctime><BR>using namespace std;<BR>void swap(int &x, int &y){int t=x;x=y;y=t;}<BR>void output (int data[], int count){<BR> for (int i=0; i<count; i++)<BR> cout<<data[i]<<'\t';<BR> cout<<endl;<BR>}<BR>void bubbleSort(int data [], int count){<BR> for ( int j = count; j >0 ; j--){<BR> for ( int i = 0 ; i < j-1; i++)<BR> if (data[i+1] < data[i] )<BR> swap(data[i],data[i+1]);<BR>};<BR>}<BR>int main(){<BR> int data[N];<BR> srand((unsigned)time(0));<BR> cout<<"排序前\n";<BR> for (int c=0;c<N;c++){<BR> data[c]=rand()%10000;<BR> cout<<data[c]<<'\t';<BR> }<BR> bubbleSort(data,N);<BR> cout<<"排序完成!!\n";<BR> output(data,N);<BR> system("PAUSE");<BR> return 0;<BR>}<BR></DIV>
<DIV id=yiv1671782922>#define N 100<BR>#include <iostream><BR>#include <cstdlib><BR>#include <ctime><BR>using namespace std;<BR>void swap(int &x, int &y){int t=x;x=y;y=t;}<BR>void output (int data[], int count){<BR> for (int i=0; i<count; i++)<BR> cout<<data[i]<<'\t';<BR> cout<<endl;<BR>}<BR>void bubbleSort(int data [], int count){<BR> for ( int j = count; j >0 ; j--){<BR> for ( int i = 0 ; i < j-1; i++)<BR> if (data[i+1] < data[i] )<BR> swap(data[i],data[i+1]);<BR>};<BR>}<BR>int main(){<BR> int data[N];<BR> srand((unsigned)time(0));<BR> cout<<"排序前\n";<BR> for (int c=0;c<N;c++){<BR> data[c]=rand()%10000;<BR> cout<<data[c]<<'\t';<BR> }<BR> bubbleSort(data,N);<BR> cout<<"排序完成!!\n";<BR> output(data,N);<BR> system("PAUSE");<BR> return 0;<BR>}<BR></DIV>
<DIV id=yiv1671782922>#define N 100<BR>#include <iostream><BR>#include <cstdlib><BR>#include <ctime><BR>using namespace std;<BR>void swap(int &x, int &y){int t=x;x=y;y=t;}<BR>void output (int data[], int count){<BR> for (int i=0; i<count; i++)<BR> cout<<data[i]<<'\t';<BR> cout<<endl;<BR>}<BR>void bubbleSort(int data [], int count){<BR> for ( int j = count; j >0 ; j--){<BR> for ( int i = 0 ; i < j-1; i++)<BR> if (data[i+1] < data[i] )<BR> swap(data[i],data[i+1]);<BR>};<BR>}<BR>int main(){<BR> int data[N];<BR> srand((unsigned)time(0));<BR> cout<<"排序前\n";<BR> for (int c=0;c<N;c++){<BR> data[c]=rand()%10000;<BR> cout<<data[c]<<'\t';<BR> }<BR> bubbleSort(data,N);<BR> cout<<"排序完成!!\n";<BR> output(data,N);<BR> system("PAUSE");<BR> return 0;<BR>}<BR></DIV>
class="p_other pic_padding">#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int& x,int& y){int t=x;x=y;y=t;}
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-1;j>=0;j--){
for (int i=0;i<j;i++)
if (data[i+1]<data[i])
swap(data[i],data[i+1]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0; c<N; c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort (data,N);
cout<<"排序完成!!\n";
output(data,N);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"Before\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"After\n";
output(data,N);
system("pause");
return 0;
}
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#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-1; j >=0; j--) {
for (int i=0;i<j;i++)
if ( data[i+1] < data[i] )
swap(data[i],data[i+1]);
};
}
int main() {
int data [N];
srand ((unsigned)time(NULL));
cout<<"排序前"<<endl;
for (int x=0;x<N;x++)
{
data[x]=rand()%10000;
cout<<"data["<<x<<"="<<data[x]<<endl;
}
bubbleSort(data, N);
cout<<"排序後"<<endl;
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
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]);
};
}
int main() {
int a[100];
srand((unsigned)time(NULL));
int i=rand();
for(int x=0; x<100; x++)
{
a[x]=rand()%10000;
}
cout<<"排序前\n";
output(a,100);
bubbleSort(a, 100);
cout<<"排序後\n";
output(a,100);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int &x, int &y){int t=x;x=y;y=t;}
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]);
};
}
int main(){
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for (int c=0;c<N;c++){
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data,N);
cout<<"排序完成!!\n";
output(data,N);
system("PAUSE");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
system("pause");
return 0;
}
#define N 100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void swap(int&x,int&y){int t=x;x=y;y=t;}
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]);
};
}
int main()
{
int data[N];
srand((unsigned)time(0));
cout<<"排序前\n";
for(int c=0;c<N;c++)
{
data[c]=rand()%10000;
cout<<data[c]<<'\t';
}
bubbleSort(data, N);
cout<<"排序完成!!\n";
output(data, N);
system("pause");
return 0;
}
張貼留言