實現方式。
using system;
public class selectionsort
public static void sort(t arr) where t : icomparable
}swap(arr, minindex, i);}}
static void swap(t arr, int i, int j)
}
測試:
using system;
using system.io;
using system.net;
using system.text;
using litjson;
namespace mycode
); // system.console.writeline(sortinghelper.issortwd(tenparray));
// sort();
// html[ clssid[103]
// webclient mywebclient = new webclient();
// //datetime time1 = datetime.now;
// mywebclient.credentials = credentialcache.defaultcredentials;//獲取或設定用於向internet資源的請求進行身份驗證的網路憑據
// system.console.writeline("未排序 :" + stringbuilder.tostring());
if (sorename.equals("selectionsort"))
else if (sorename.equals("insertionsort"))
else if (sorename.equals("insertionsort2"))
else if (sorename.equals("mergesort"))
watch.stop(); //停止監視
// stringbuilder stringbuilder2 = new stringbuilder();
// for (var i = 0; i < dataarray.length; i++)
// // system.console.writeline("已經排序:" + stringbuilder2.tostring());
timespan timespan = watch.elapsed; //獲取當前例項測量得出的總時間
if (!sortinghelper.issortwd(dataarray))
string log = string.format("排序的名字【】,排序的執行時間【(毫秒)】 排序陣列長度【】", sorename, timespan.totalmilliseconds, dataarray.length);
system.console.writeline(log);
}public static t testselectionsortperformance(t tenparray) where t : icomparable
public static void testselectionsort()
;string selecta = ;
student students = ;
selectionsort.sort(arr);
selectionsort.sort(selecta);
selectionsort.sort(students);
equatable(arr);
equatable(selecta);
equatable(students);
}public static void equatable(t data)
system.console.writeline(stringbuilder.tostring());
}public static void testgenerate()
static void xxcz()
;string strs = ;
// student students = ;
// // var res = 線性查詢.search(data, 12);
// // var res = 線性查詢.search(strs, "ss");
// var res = 線性查詢.search(students,
// new student("qq"));
// system.console.writeline("res :" + res);
}static void testnumber()
, hash code = ", n, n.gethashcode());}}
}}public struct number
public int value
}public override bool equals(object obj)
public override int gethashcode()
public override string tostring()
}// the example displays output like the following:
// n = -634398368, hash code = -634398368
// n = 2136747730, hash code = 2136747730
// n = -1973417279, hash code = -1973417279
// n = 1101478715, hash code = 1101478715
// n = 2078057429, hash code = 2078057429
// n = -334489950, hash code = -334489950
// n = -68958230, hash code = -68958230
// n = -379951485, hash code = -379951485
// n = -31553685, hash code = -31553685
// n = 2105429592, hash code = 2105429592
using system;
public class arraygenerator
public static int generateorderarray(int n)
return arr;
}public static int generateorderarray(int n, int min, int max)
return arr;
}}
選擇排序C 實現
演算法描述 首先找到陣列中最小的元素,將它與陣列第乙個元素進行交換,接著在剩下的元素中找的最小的元素與陣列第二個元素進行交換,如此往復,直到整個陣列都排序。下面給出整型陣列的實現,其他複雜型別只需實現自定義的比較函式即可 include include using namespace std con...
C 實現選擇排序
選擇排序 selectsort 是一種簡單直觀的排序演算法。演算法原理 第一次從待排序的資料元素中選出最小 或最大 的乙個元素,存放在序列的起始位置,然後再從剩餘的未排序元素中尋找到最小 大 元素,然後放到已排序的序列的末尾。以此類推,直到全部待排序的資料元素的個數為零。選擇排序是不穩定的排序方法。...
c 實現選擇排序
說明 是我親自碼的,除錯通過的,中有演算法思想和詳細的注釋,一目了然。專案已經上傳到我的github 專案中還有另外得九種排序演算法的c 實現 以及其思想。1 選擇排序 2 插入排序 3 氣泡排序 4 希爾排序 5.1 歸併排序遞迴實現 5.2 歸併排序非遞迴實現 6.1 快速排序遞迴實現 6.2 ...