Sort Big Synthesis

Source: Internet
Author: User
Tags min sort
sort Big Synthesis
Sort big comprehensive test I remember.

#include <iostream> #include <stdlib.h> #include <string.h> using namespace std;
    void Bubblesort (int a[], int n) {if (NULL = = A | | n = = 0) {return; } for (int i = n-1; i > 0, i--) {for (int j = 0; J < i; J + +) {if (A[j] > a[
            J + 1]) {swap (a[j], a[j+ 1]);
    }}}} void Insertsort (int a[], int n) {if (NULL = = A | | n = = 0) {return;
    } Int J;
        for (int i = 1; i < n; i++) {j = i;  
            while (J > 0 && a[j] < a[j-1]) {swap (a[j-1], a[j]);
        j--;
    }}} void Merge (int a[], int l, int mid, int r) {int leftsize = mid-l + 1;

    int rightsize = R-mid;  
    int *left = new Int[leftsize];

    int *right = new Int[rightsize];
    for (int i = 0; i < leftsize; i++) {Left[i] = a[l + i]; } for (int i = 0; i < rightsize;
    i++) {Right[i] = A[mid + i + 1];
    } int i = 0, j = 0, k = l; while (I < leftsize && J < rightsize) {if (Left[i] < right[j]) {a[k++] =
        Left[i++];
        } if (Left[i] > Right[j]) {a[k++] = right[j++];
    }} while (I < leftsize) {a[k++] = left[i++];
    } while (J < rightsize) {a[k++] = right[j++];
    } free (left);
Free (right);
        } void MergeSort (int a[], int l, int r) {if (L < r) {int mid = (L + r)/2;
        MergeSort (A, L, mid);
        MergeSort (A, mid + 1, R); 
    Merge (A, L, Mid, R); }} void QuickSort (int a[], int left, int. right) {if (left < right) {int i = left, j = right, key = a
        [Left];
        while (I < J && A[j] > key) {j--;
        } if (I < j) {a[i++] = a[j]; } WHile (i < J && A[i] < key) {i++;
        } if (I < j) {a[j--] = A[i];
        } A[i] = key;
        QuickSort (A, left, I);
    QuickSort (A, i + 1, j);
    }} void Choosesort (int a[], int n) {int min, index;
        for (int i = 0; i < n; i++) {min = a[i];
                for (int j = i + 1; j < N; j + +) {if (A[j] < min) {min = a[j];
            index = j;
    }} swap (A[i], a[index]);

    }} void Shellsort (int a[], int n) {int d = n;
        while (d) {d = D/2; for (int i = 0; i < n-d; i++) {if (A[i] > a[i + d]) {swap (a[i], a[
            I+d]);

    }}}} void Adjustheap (int a[], int start, int end) {int value = A[start]; for (int i = 2*start + 1; I <= end; I *= 2) {if (I < end && A[i] > A[i + 1]) {i++;
            } if (Value > A[i]) {A[start] = A[i];
        start = i;
        } else {break;
}} A[start] = value; } void Heapsort (int a[], int n) {//Build a large top heap for (int i = N/2-1; I >= 0; i--) {Adjustheap (A, I, N)
    ;
        }//heap sort for (int i = n-1; i > 0; i--) {swap (a[0], a[i]);
    Adjustheap (A, 0, i-1);
    }} int main () {int *arr = new int;

    int n = 0;
    CIN >> N;
    for (int i = 0; i < n; i++) {cin >> arr[i];
    }//bubblesort (arr, n);
    Insertsort (arr, n);
    MergeSort (arr, 0, n-1);
    QuickSort (arr, 0, n-1);
    Choosesort (arr, n);
    Shellsort (arr, n);
    Binaryinsertsort heapsort (arr, n);
    for (int i = 0; i < n; i++) {cout << arr[i] << "";
    } system ("Pause");   
return 0; }

PS: Stability can be judged based on whether the relative position of the two same digits will change.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.