选择排序 - Ctrl+C&Ctrl+V - ITeye博客

白诗秀儿 关注

收藏于 : 2017-09-22 17:19   被转藏 : 1   

选择排序        排序动画




 
 

 

 

import java.util.Arrays;
 

/**
 * 选择排序
 * @author baoy
 *
 */
public class SelectionSort {
	
	public static void main(String[] args) {
		int []a = {49,38,65,97,76,13,27,14,10};
		sort(a);
		System.out.println(Arrays.toString(a));
	}
	
	public static void sort(int [] a){
		for (int i = 0; i < a.length; i++) {
			int temp = i;
			for (int j = i+1; j < a.length; j++) {
				if (a[temp] > a[j]) {
					temp = j;
				}
			}
			if (temp != i)  
				swap(a, i, temp);
		}
	}

	public static int[] swap(int[] a, int i, int j) {
		int temp = a[i];
		a[i] = a[j];
		a[j] = temp;
		return a;
	}
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者 

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

 

个人主页http://knight-black-bob.iteye.com/



 
 
 谢谢您的赞助,我会做的更好!

  • 大小: 13.1 KB
  • 大小: 41.2 KB
分享到:
参考知识库
Android知识库 37286  关注 | 3149  收录
React知识库 3464  关注 | 393  收录
人工智能基础知识库 16143  关注 | 212  收录
Java 知识库 33967  关注 | 3748  收录
评论
knight_black_bob
  • 浏览: 181667 次
  • 性别:
  • 来自: 北京
社区版块
存档分类
最新评论
 阅读文章全部内容  
点击查看
文章点评
相关文章
白诗秀儿 关注

文章收藏:1308

TA的最新收藏