bubble sort就不寫了, 基數排序以後補
using system;
namespace datastructurepractice
input[j]
= tmp;}}
public
static
void
shellsort
(t input,
int length)
input[j]
= tmp;}}
}public
static
void
******selectsort
(t input,
int length)
}t tmp = input[minindex]
; input[minindex]
= input[i]
; input[i]
= tmp;}}
public
static
void
heapsort
(t input,
int length)
for(
int i = length -
1; i >
0; i--)}
private
static
void
percdown
(t input,
int root,
int end)
if(input[child]
.compareto
(tmp)
>0)
else
break;}
input[root]
= tmp;
}public
static
void
mergesort
(t input,
int length)
public
static
void
mergesortalter
(t input,
int length)
else
if(lpos + step <= length -1)
//即,此時剩餘元素大於乙個組,小於兩個組
//當剩餘元素小於等於乙個組時, 本次迴圈什麼也不做, 等待下次迴圈中被併入另乙個標準長度的組}}
}private
static
void
msort
(t input, t[
] tmparry,
int left,
int right)
}private
static
void
merge
(t input, t[
] tmparry,
int lpos,
int rpos,
int rend)
else
tmppos++;}
//複製剩餘陣列至臨時組
while
(lpos <= lend)
while
(rpos <= rend)
//將有序的臨時組複製回輸入組
for(
int i =
0; i < nums; i++)}
public
static
void
quicksort
(t input,
int length)
private
static
void
qsort
(t input,
int left,
int right)
input[low]
= input[high]
;while
(low < high && input[low]
.compareto
(pivot)
<=0)
input[high]
= input[low];}
input[low]
= pivot;
qsort
(input, left, low -1)
;qsort
(input, low +
1, right)
;return;}
}public
static
void
quicksortweiss
(t input,
int length)
private
static
void
qsortweiss
(t input,
int left,
int right)
while
(input[
--high]
.compareto
(pivot)
>0)
if(low < high)
else
break;}
swap
(ref input[low]
,ref input[right -1]
);qsortweiss
(input, left, low -1)
;qsortweiss
(input, low +
1, right);}
else
input[j]
= tmp;}}
}private
static
tmedianpivot
(t input,
int left,
int right)
if(input[left]
.compareto
(input[right]
)>0)
if(input[middle]
.compareto
(input[right]
)>0)
swap
(ref input[middle]
,ref input[right -1]
);return input[right -1]
;}private
static
void
swap
(ref
t a,
reft b)
}}
資料結構練習 堆排序
只是把以前的寫的 貼出來而已 ifndef heap h define heap h void heapsort int a,int arraysize void buildheap int a,int arraysize void shiftup int a,int index void shif...
資料結構 排序(C )
直接插入排序 時間複雜度 o n 2 空間複雜度 o 1 void insertsort int r,int n for j i 1 j high j 將high後面的元素全部後移一位 r j 1 r j r high 1 temp 插入元素 希爾排序 時間複雜度 o n 2 空間複雜度 o 1 v...
資料結構練習
include include define size 20 typedef struct list 重新命名結構體 list t 建立 list t creat list int size list length 0 空表初始化,實際長度為0 return list 返回堆區申請的首位址 判空 i...