多種引數排序說明
』定義乙個類
public class clssort
implements icomparable '必須要是繼續的
private mvarid as integer
public property id() as integer
getreturn mvarid
end get
set(byval value as integer)
mvarid = value
end set
end property
private mvarname as string
public property name() as string
getreturn mvarname
end get
set(byval value as string)
mvarname = value
end set
end property
private mvarother as string
public property other() as string
getreturn mvarother
end get
set(byval value as string)
mvarother = value
end set
end property
sub new()
end sub
sub new(byval pid as integer, byval pname as string, byval pother as string)
mvarid = pid
mvarname = pname
mvarother = pother
end sub
public function compareto(byval obj as object) as integer implements system.icomparable.compareto
dim mtemp as clssort = ctype(obj, clssort)
if me.mvarid > mtemp.mvarid then
return 1
elseif me.mvarid < mtemp.mvarid then
return -1
else
return 0
end if
end function
public class namecomparer
implements icomparer
public function compare(byval x as object, byval y as object) as integer implements system.collections.icomparer.compare
dim c1 as clssort = ctype(x, clssort)
dim c2 as clssort = ctype(y, clssort)
return string.compare(c1.name, c2.name)
end function
end class
public class othercomparer
implements icomparer
public function compare(byval x as object, byval y as object) as integer implements system.collections.icomparer.compare
dim c1 as clssort = ctype(x, clssort)
dim c2 as clssort = ctype(y, clssort)
return string.compare(c1.other, c2.other)
end function
end class
public shared readonly property sortbyname() as icomparer
getreturn new namecomparer
end get
end property
public shared readonly property sortbyother() as icomparer
getreturn new othercomparer
end get
end property
end class
'''測試方法
dim myauto(4) as clssort
myauto(0) = new clssort(1, "aa", "zz")
myauto(1) = new clssort(22, "bb", "xx")
myauto(2) = new clssort(3, "cc", "yy")
myauto(3) = new clssort(4, "ee", "hh")
myauto(4) = new clssort(52, "dd", "aa")
console.writeline("----before sort-----")
for each c as clssort in myauto
console.writeline("序號:,名稱:,其它:", c.id, c.name, c.other)
next
console.writeline()
array.sort(myauto)
' array.reverse(myauto)
console.writeline("----after sort by id-----")
for each c as clssort in myauto
console.writeline("序號:,名稱:,其它:", c.id, c.name, c.other)
next
console.writeline()
'array.sort(myauto, new clssort.namecomparer)
array.sort(myauto, clssort.sortbyname)
console.writeline("----after sor by name-----")
for each c as clssort in myauto
console.writeline("序號:,名稱:,其它:", c.id, c.name, c.other)
next
console.writeline()
' array.sort(myauto, new clssort.othercomparer)
array.sort(myauto, clssort.sortbyother)
console.writeline("----after sor by other-----")
for each c as clssort in myauto
console.writeline("序號:,名稱:,其它:", c.id, c.name, c.other)
next
console.writeline()
多種排序組合
include void bubble int a,int n 氣泡排序 void choise int a,int n 選擇排序 void quick int a,int i,int j 快速排序 void insert int a,int n 插入法 void shell int a,int n...
多種字元編碼集的說明
計算機只能識別二進位制資料,早期由來是電訊號。為了方便應用計算機,讓它可以識別各個國家的文字。就將各個國家的文字用數字來表示,並一一對應,形成一張表。這就是編碼表。iso8859 1 拉丁碼表。歐洲碼表 gb2312 中國的中文編碼表。最多兩個位元組編碼所有字元 unicode 國際標準碼,融合了目...
java 多種排序演算法
1 時間頻度 乙個演算法中的語句執行次數叫做語句頻度或時間頻度,用t n 表示。理論上無法計算乙個演算法執行所需的時間,必須上機測試才能知道,但是我們不可能也沒必要對每個演算法都進行上機測試,我們只需要知道哪個演算法執行時間長,哪個演算法執行時間短即可。演算法花費的時間和演算法中語句執行次數成正比,...