您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C# 选择排序

2024/3/3 11:30:46发布16次查看
c# 选择排序
using system; using system.collections.generic; using system.linq; using system.text; namespace sort { class selectsorter { public static int[] sort(int[] a) { selectsort(a); return a; } private static void selectsort(int[] myarray) { int i, j, smallest; //数据起始位置,从0到倒数第二个数据 for (i = 0; i < myarray.length - 1; i++) { smallest = i;//记录最小数据的下标 for (j = i + 1; j < myarray.length; j++) { //在剩下的数据中寻找最小数据 if (myarray[j] < myarray[smallest]) { smallest = j;//如果有比它更小的,记录下标 } } //将最小数据和未排序的第一个数据交换 swap(ref myarray[i], ref myarray[smallest]); } } private static void swap(ref int left, ref int right) { int temp; temp = left; left = right; right = temp; } } }
选择排序的思想:
例子:
以上就是c# 选择排序的内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product