-
算法 排序 直接选择排序(Straight Selection Sort)
void SelectSort(SeqList R)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
int i,j,k;
for(i = 1; i < n; i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// 做第i趟排序(1≤i≤n-1)
k = i;
for(j = i + 1; j <= n; j++) // 在当前无序区R[i..n]中选key最小的记
![](/Images/OutliningIndicators/InBlock.gif)
录R[k]
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(R[j].key < R[k].key)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
k = j; // k记下目前找到的最小关键字所在的位置
}
}
if(k != i)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// 交换R[i]和R[k]
R[temp] = R[i];
R[i] = R[k];
R[k] = R[temp]; // R[temp]作暂存单元
} // endif
} // endfor
} // SeleetSort
![](/Images/OutliningIndicators/None.gif)
void SelectSort(int[] x)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
for(int i = 0; i < x.Length - 1; i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// 只需做n-1次循环
int min = i;
for(int j = i + 1; j < x.Length; j++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(x[j] < x[min])
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
min = j;
}
}
if(min != i)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// 交换x[i]和x[k]
int temp;
temp = x[i];
x[i] = x[min];
x[min] = temp;
} // endif
} // endfor
} // SelectSort
-
相关阅读:
python- 冒泡算法
python-文件读写资料整理
Python学习之edx6001-week4
Python学习之自动化开发-DAY1作业-三级菜单
python学习之自动化开发-DAY1作业-登陆程序
python 学习之edx6001-week4
elasticsearch RESTfull _cat api
python
python
python 文件操作
-
原文地址:https://www.cnblogs.com/xiaodi/p/296499.html
Copyright © 2020-2023
润新知