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

📄 selectsort.cpp

📁 包含8种常用的排序。如快速排序
💻 CPP
字号:
#include <iostream.h>
#include <stdio.h>
#include <time.h>
#include<stdlib.h>
#include <string.h>
#include <conio.h>
#include <algorithm>
using namespace std;
#define N 10000
int a[N];

void SelectSort()
{  int i,j;
   int index;
   for(i=0;i<N-1;i++)
   {   index=i;
	   for(j=i+1;j<N;j++)
		   if(a[j]<a[index]) 
			   index=j;
		   swap(a[i],a[index]);
   }
   for(i=0;i<N-1;i++)
   {
	  cout<<a[i]<<"->";
   }
   cout<<a[N-1]<<"\n";
}

 void main()
{ 
   clock_t start=clock();/*程序开始运行的时间*/
   int k;
   
   //srand((unsigned int)time(NULL));//随时间的不同产生不同的随机数
   for(k=0;k<N;k++)
		a[k]=rand()%N+1;

   SelectSort();

   clock_t end=clock();/*程序结束运行的时间*/
   cout<<"整个程序运行的时间为:";
   cout<<(end-start)<<"毫秒\n";
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -