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

📄 selectsort.c

📁 选择排序
💻 C
字号:
#include <stdio.h>
#include "buildarray.c"
#include "sort.h"
unsigned long int compare=0,move=0;


void SelectSort(int *p,int n)
{
	int i,j,count=0;
	int min,temp;
	for(i=0;i<n-1;i++){
		min=i;
		for(j=i+1;j<n;j++){
			if(*(p+j)<*(p+min)){
				min=j;
				compare++;
			}
		}
		if(min!=i){
			temp=*(p+i);
			*(p+i)=*(p+min);
			*(p+min)=temp;
			move+=3;
		}
	}
	printf("the queue sorted by selectsort is:\n");
	for(i=0;i<n;i++){
		printf("%d	",*(p+i));
		count++;
		if(count%10==0)
		printf("\n");
	}
}


main()
{
	//int Queue[9]={8,5,6,9,2,1,3,4,7};
	SelectSort(BuildArray(),NUM);
	printf("SelectSort compare=%ld,move=%ld",compare,move);
	printf("\n");	
}

⌨️ 快捷键说明

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