C#学习笔记—数组的选择排序
2010-06-18 00:30
281 查看
//方法类 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cp4 { class SelectSorter { //按由小到大的顺序,对数组进行排序 public static void SelectSortAscending(int[] arr) { for (int i = 0; i < arr.Length-1; i++) { for (int j = i+1; j < arr.Length; j++) { if (arr[i] > arr[j]) //由大到小:arr[i] < arr[j] { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } } //遍历打印出数组 public static void PrintArray(int[] arr) { foreach (int pint in arr) { Console.WriteLine(pint); } } } } //测试类 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cp4 { class Test { public static void Main(string[] agrs) { int[] a = {45,65,78,12,36}; SelectSorter.SelectSortAscending(a); //由于是静态方法,不用实例 SelectSorter.PrintArray(a); } } }
相关文章推荐
- 数组-选择排序
- 实现整形数组的选择排序
- java面试题8--数组高级-选择排序
- Java基础(5) -数组排序(冒泡 选择)
- java-数组静态初始化、选择排序、冒泡排序、数组的折半查找、折半查找练习
- 浅谈java中整型数组选择排序的思想
- Java对一维数组排序:冒泡,选择,插入,比较效率
- JAVA-选择排序从控制台输入数组
- 对数组进行选择排序
- 数组选择排序和冒泡排序
- Java基础总结 - 数组排序之选择排序
- 数组的遍历,获取最大值,数组的反转,数组中元素的查找、冒泡排序、选择排序、折半查找法
- 常见对象_数组高级选择排序原理图解、数组高级选择排序代码实现
- c++ 数组排序(选择, 冒泡, 插入,快速)
- 数组冒泡排序,选择排序,逆序,折半查找,遍历方法
- day04获取数组的最值,选择排序,冒泡排序,折半查找
- 使用指针法对数组进行冒泡排序、选择排序、插入排序法、二分查找法
- C语言 选择排序算法原理和实现 从数组中 找出最小的元素然后交换位置
- 怎样编写一个程序,把一个有序整数数组放到二叉树中? 编写实现链表排序的一种算法。说明为什么你会选择用这样的方法?
- 数组的常见操作:冒泡排序 选择排序与取最值