笔记-数据结构
参考:《天勤-数据结构高分笔记》
[TOC]
绪论
线性表
栈和队列
串
数组,矩阵与广义表
树与二叉树
图
排序
选择类排序
简单选择排序
思路:从无序序列中选一个最小的关键字与无序序列的第一位交换,从而无序序列-1,有序序列+1;如此循环
代码
Code1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33/**
从无序序列中选一个最小的关键字与无序序列的第一位交换,从而无序序列-1,有序序列+1;如此循环
*/
#include <stdio.h>
void SelectSort(int R[],int n){//R:disoder array n:array long
int i,j,k,temp;
for(i=0;i<n;++i){//pick one from disorder to order every time
k=i;//R[k] store the smallest
for(j=i+1;j<n;++j){//pick the smallest
if(R[j]<R[k]){
k=j;
}
}
//swith it(R[j-1]) with the [first disorder one]
temp=R[k];
R[k]=R[i];
R[i]=temp;
}
}
int main(int argc, char const *argv[])
{
int R[]={49,38,65,97,76,13,27,49};
int n = sizeof(R)/sizeof(int);
int i;
SelectSort(R,n);
for(i=0;i<n;++i){
printf("%4d",R[i]);
}
return 0;
}

