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

📄 selectsort.cpp

📁 数据结构c++-书的一些源代码
💻 CPP
字号:
#include <iostream.h>
#include "datatype.h"

void SelectSort(datatype a[], int n)
/*用直接选择排序法对a[0]--a[n-1]排序*/
{
	int i, j, small;
	datatype temp;

	for(i=0; i < n-1; i++)
	{
		small = i;
		for(j = i+1; j < n; j++)
			if(a[j].key < a[small].key) small=j;

		if(small != i)
		{
			temp = a[i];
			a[i] = a[small];
			a[small] = temp;
		}
	}
}

void main(void)
{
	datatype test[6]={64,5,7,89,6,24};
	int n = 6;
	SelectSort(test,n);
	for(int i=0; i<n; i++)
		cout << test[i].key << "  ";
}

⌨️ 快捷键说明

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