?? 排序算法.cpp
字號:
// 排序算法.cpp: 主項目文件。
#include "stdafx.h"
#include<iostream>
#include<ctime>
#include<string>
#include<iomanip>
#include<cstdlib>
using namespace std;
int selectScroe(int *,int);
int main()
{
srand(time_t(NULL));
int length;
cout<<"請輸入數列的數目"<<endl;
cin>>length;
int *p=new int[length];
for(int i=0;i<length;i++)
{
p[i]=rand()%100;
cout<<setw(4)<<p[i]<<endl;
}
selectScroe(p,length);
for(int i=0;i<length;i++)
{
cout<<setw(4)<<p[i]<<endl;
}
system("PAUSE");
return 0;
}
int selectScroe(int p[],int n)
{
double time,time1;
time=time_t(NULL);
for(int i=n-1;i>0;i--)
{
for(int j=0; j<i; j++)
{
if(p[j] > p[j+1])
{
int temp;
temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
}
}
}
time1=time_t(NULL);
time=time1-time;
cout<<"花費的時間為"<<time<<endl;
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -