利用srand(), rand()產生值為0~9999的int亂數存入陣列a[100],
利用 bubblesort排序a!
herrDeng網內搜尋
自訂搜尋
Ads
2010年5月25日 星期二
訂閱:
張貼留言 (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 C++使用字串find迴圈速解Leetcode 2490 Circular Sentence C++ & Python都有字串的find,用法都類似 split=s.find(' ', split+1)能找到s從index=split+1開...
-
Python CPP heap priority queue速解L eetcode 2530. Maximal Score After Applying K Operations heap/priority queue是重要的資料結構,無論是C++的std::priority_q...
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;
}
張貼留言