---
title: "3.排序-选择类排序"
author: "wangkechao.dream"
date: "2013-08-28T12:08:23Z"
tags: []
categories: ["编程语言"]
slug: "3"
draft: false
lastmod: "2013-08-29T14:46:34Z"
id: 1932015
url: "https://dreamworld.iteye.com/blog/1932015"
---

1\. 简单选择排序

简单选择排序(Simple Select Sort)算法的基本思想是：从待排序的记录序列中选择关键码最小（或最大）的记录并将它与序列中的第一个记录交换位置；然后从不包括第一个位置上的记录序列中选择关键码最小（或最大）的记录并将它与序列中的第二个记录交换位置；如此重复，直到序列中只剩下一个记录为止。

 

```
package sort.select;


/**
 * 简单选择排序
 * 
 * @author king
 *
 */
public class SimpleSelectSort {
	private static void simpleSelectSort(int[] data){
		int temp; //临时存储变量
		int point;//定位交换的位置
		int count=1;
		for(int i=0;i<data.length;i++){
			point=i;
			for(int j=i+1;j<data.length;j++){
				if(data[point]>data[j]){
					point=j;
				}
			}
			//交换位置
			temp=data[i];
			data[i]=data[point];
			data[point]=temp;
			System.out.println("第" + count + "趟排序:");
			for (int k = 0; k < data.length; k++) {
				System.out.print(data[k] + " ");
			}
			System.out.print("\n");
			count++;
		}
	}
	public static void main(String[] args) {
		int[] data = new int[]{3,43,5,2,4};
		simpleSelectSort(data);
	}
}
```

 第1趟排序:

2 43 5 3 4 

第2趟排序:

2 3 5 43 4 

第3趟排序:

2 3 4 43 5 

第4趟排序:

2 3 4 5 43 

第5趟排序:

2 3 4 5 43 

 

2\. 堆排序【有些难，我要想几天呢。。。。】