Select sort
selection sorting is a simple and intuitive sort algorithm whose core idea is to traverse an array, find the smallest element in a sequence that has never been sorted, and place it at the end of the sorted sequence.
Complexity of Time: O (n^2)
Stability: Unstable
* * @brief selection Sort
*
/void Selection_sort (int a[], int n)
{
int i, J, Min, tmp;
for (i = 0; i < n-1; ++i) {
min = i;
for (j = i+1 J < n; ++j) {
if (A[j] < a[min]) {
min = j;
}
}
if (min!= i) {
tmp = a[min];
A[min] = A[i];
A[i] = tmp;}}}
Direct Insert Sort
Direct insertion Ordering is a relatively easy to understand sort algorithm whose core idea is to traverse an array and insert elements of the array into the sorted sequence.
Complexity of Time: O (n^2)
Stability: Stability
Realize:
/* @brief insetion Sort
* Insert the new element
to the sorted subarray
/void Insertion_sort (int a[], in T n)
{
int i, j, num;
for (i = 1; i < n; ++i) {
num = a[i];
for (j = i-1 J >= 0 && a[j] > num;--j)
a[j+1] = a[j];
A[J+1] = num;
}
}
Bubble Sort
Bubble Sort is one of the most basic sorting algorithms, whose core idea is to traverse the array from the back forward, comparing a[i] and a[i-1], if a[i] is smaller than a[i-1, then exchange the two. After such a traversal, the smallest element is at the top of the array, followed by the traversal of the child array except for the smallest element. N-Time (n-array elements) after the traversal is arranged. The outer loop is n times, the inner layer cycle is n-1, n-2 ... 1 times.
Complexity of Time: O (n^2)
Stability: Stability
Realize:
/* @brief bubble sort * move "
smallest element to" front in every single loop/
void
bubble_sor T (int a[], int n)
{
int i, J, TMP;
for (i = 0; i < n; ++i) {for
(j = n-1; j > i;--j) {
if (A[j] < a[j-1]) {
tmp = a[j];
A[J] = a[j-1];
A[J-1] = tmp;}}}