Insert sort-Pseudo code--Flowchart--Program

Source: Internet
Author: User




Insert sort pseudo code for I <--1 to n-1 for J <--i-1 to 0 if a[i] > a[j] breakif j!=i-1temp <--a[i]for k &L t;--i to j+2 A[k] <--a[k-1]a[j+1] <--Temp

 

 Inserting a sort flowchart

  

Insert Sort Code Implementation

  

/*** to sort an array a[],the length of a shouldn ' t being negative* and after the sort,the content of array a have changed.* * @parm a[] The array to be sorted* @parm len the length of the array A * * @return there is no return,only to sort the ARRA Y*/void insertsort (int a[], int len) {int temp;//used to save the value of a[i]/*** to find the place of the element which  Index is i* we think, the first element a[0] is on the right place* next we find the place for elements which index is From 1 to n-1*/for (int i = 1, i < n; i++) {/*** We would find the place for the element which index is I if* the value of A[i] is bigger the a[j],so we break to does next thing*/for (int j = i-1; J >= 0; j--) {if (A[i] > A[j]) break;} /*** If the value J is not equals to I-1,we would know then the place of a[i]* are not i-1,so we had to move all the Eleme NT which index is bigger than j* and next we put element A[i] to the place which index is j+1*/if (j!=i-1) {temp = A[i];for ( int k = i; K > j+1; k--) {a[K] = a[k-1];} A[J+1] = temp;}}}

  

Insert sort-Pseudo code--Flowchart--Program

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.