selectsort1.txt
来自「selection排序法」· 文本 代码 · 共 46 行
TXT
46 行
//**************************************
//
// Name: Select Sort
// Description:This will sort an array o
// f integers using the select sort algorit
// hm.
// By: MaLord
//
// Inputs:An array of integers and the n
// umber of items in the array.
//
void select_sort(int array[], int size)
{
//Go through the array comparing every n
// umber
//with every number after it,
//if the first number is bigger then swa
// p the data
for (int i = 0; i < size-1)
{
for (int compare = i+1; compare < size; compare++)
{
if (array[i] > compare[i])
swap(array[i], compare[i]);
}
}
}
void swap(int &first, int &second)
{
//For a swap, a temporary variable must
// be used
int temp = first;
first = second;
second = temp;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?