摘要: 选择排序的概念就是从未排序中选择最小的元素放入到已排序元素的最后面。下面是对一组整数进行排序。 1 public class selectionSort { 2 public static void main(String[] args){ 3 int[] toBeSorted = {1,54,3,8,6,0}; 4 5 6 for(int i = 0; i < toBeSorted.length; i++){ 7 for(int j = i+1; j < toBeSorted.length; ... 阅读全文
posted @ 2012-12-19 21:06 繁星苑 阅读(4000) 评论(0) 推荐(0) 编辑
摘要: 现在刚开始学习java。今天写一个swap,让我对java没有指针这个事情深有体会。由于我想是把swap()当成一个函数来写,因此我尝试这样的方式。private static void swap(int &a, int &b){ int temp = a; a = b; b = temp;} 我发现在eclipse中是有错误的,java中的参数传递都是采用值传递的传递方式,因此不能使用引用符号。 后面我发现可以使用重新赋值的方法:private static int[] swap(int a, int b){ int temp = a; a = b; ... 阅读全文
posted @ 2012-12-19 11:18 繁星苑 阅读(3625) 评论(1) 推荐(0) 编辑