⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 排序算法.cpp

📁 数据结构上让我们编写的排序算法
💻 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 + -