Insert Sort 2.0

Source: Internet
Author: User

Long time no review of the previous written data structure, today read a paragraph before the insertion sort.

Insertion sorting principle: Popular speaking, and playing poker cards is a truth, from a pile of Chaos card, a card, take one after the front row with the cards to compare, insert the appropriate position.

Complexity of Time: O (n^2)

/*Insert Sort 2.0** This version will create an array function to delete, * * Create an array with an insert sort orchestration into the same function. */#include"stdafx.h"#include<stdio.h>#defineM 1000voidInsert_sorting (intA[],intn);//Insert SortvoidOut_put (intA[],intn);//Output ArrayintMain () {intN; intA[m] = {0}; printf_s ("Enter the number to be sorted \ n"); printf_s ("n="); scanf_s ("%d", &N);    Insert_sorting (A,n);    Out_put (A, n); return 0;}voidInsert_sorting (intA[],intN) {    intI, J, WEP;//WEP is intermediate variableprintf_s ("Please enter a 1th value ="); scanf_s ("%d", &a[0]);  for(i =1; I < n; i++) {printf_s ("Please enter%d value =", i+1); scanf_s ("%d", &A[i]);  for(j = i;; j--)        {            if(J = =0)            {                 Break; }            if(A[j] < a[j-1]) {WEP= A[j-1]; A[j-1] =A[j]; A[J]=WEP; }            Else            {                 Break; }        }    }}voidOut_put (intA[],intN) {    inti;  for(i =0; I < n; i++) {printf_s ("%d", A[i]); }}

Insert Sort 2.0

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.