void mysort::
bubblesort
(std::vector<
int>
&in)}}
}
void mysort::
selectsort
(std::vector<
int>
&in)}if
(minindex != i)
}}
void mysort::
insertsort
(std::vector<
int>
&in)
in.at(j +1)
= temp;
}}
void mysort::
quicksort
(std::vector<
int>
&in,
int begin,
int end)
in.at(i)
= in.
at(j)
;while
(i < j && in.
at(i)
<= key)
in.at(j)
= in.
at(i);}
in.at(i)
= key;
quicksort
(in, begin, i -1)
;quicksort
(in, i +
1, end)
;}
void mysort::
shellsort
(std::vector<
int>
&in)
in.at(j + gap)
= temp;
} gap /=2
;}}
/// 桶排序適合任意序列不超過某值,且序列無重複
void mysort::
bucketsort
(std::vector<
int>
&input)
;for each (
int var in input)
int index =0;
for(size_t i =
0; i < max; i++)if
(index == input.
size()
)}}
void mysort::
mergesort
(std::vector<
int>
&in,
int left,
int right,
int*temp)
int mid =
(right + left)/2
;mergesort
(in, left, mid, temp)
;mergesort
(in, mid +
1, right, temp)
;//merge
int i = left, j = mid +
1, index =0;
//int *temp = (int *)malloc(sizeof(int) * (right - left)); //動態分配記憶體會出錯
//int *temp = new int(right - left);
while
(i <= mid && j <= right)
else
}while
(i <= mid)
while
(j <= right)
index = left;
while
(index <= right)
//free(temp);
//deletetemp;
}
演算法時間複雜度
空間複雜度
穩定性氣泡排序
o(n2)
o(1)
穩定選擇排序
o(n2)
o(1)
不穩定插空排序
o(n2)
o(1)
穩定快速排序
o(nlogn)
o(logn)
不穩定桶排序
o(n+k)
o(n+k)
穩定希爾排序
和增量有關,如5.2的增量序列時為o(n3/2)
o(1)
不穩定歸併排序
o(nlogn)
o(n)
穩定
C 排序演算法
最基本的 氣泡排序 c code using system namespace bubblesorter j public class mainclass bubblesorter sh new bubblesorter sh.sort iarrary for intm 0 m iarrary.le...
C 排序演算法
protected int bubbleup int array 氣泡排序 return array public int selectionsorter int list 選擇排序 int temp list min list min list i list i temp return list ...
C 演算法排序
不廢話,上 using system using system.collections.generic using system.linq using system.text using system.threading.tasks namespace 排序演算法 陣列 氣泡排序 選則排序 arra...