selectsort.cpp

来自「四种排序算法的比较」· C++ 代码 · 共 52 行

CPP
52
字号
// SelectSort.cpp: implementation of the SelectSort class.
//
//////////////////////////////////////////////////////////////////////

#include "SelectSort.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SelectSort::SelectSort()
{

}

SelectSort::~SelectSort()
{

}

void SelectSort::selectSort()
{
	int i,j,min,temp;
	for(i=0;i<SelectSort::Count-1;i++)
	{
		min=i;
		for(j=i+1;j<SelectSort::Count;j++)
			if(SelectSort::data[j]<SelectSort::data[min])
			min=j;
		if(min!=i)
		{
			temp=SelectSort::data[min];
			SelectSort::data[min]=SelectSort::data[i];
			SelectSort::data[i]=temp;
		}
	}
} 

void SelectSort::Init(int n)
{
	data=new int[n];
	Count=n;
	cout<<"Please input the data:"<<endl;
	for(int i=0;i<n;i++)
		cin>>data[i];
} 
void SelectSort::Show()
{
	cout<<"The result is:"<<endl;
	for(int i=0;i<SelectSort::Count;i++)
		cout<<data[i]<<"  ";
} 

⌨️ 快捷键说明

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