Dick Silk needs to be attacked. Learn C + + and algorithm------Insert sort

Source: Internet
Author: User

1#include <iostream>2 using namespacestd;3 intInsertsort (intArray[],intn);4 intOutPut (intArray[],intn);5 intMain ()6 {7     intarray[]={5,2,4,6,1,3};8Insertsort (Array,6);9OutPut (Array,6);Ten     return 0; One } A  - intInsertsort (intArray[],intN) - { the      for(intI=1; i<n;i++)//start with the second card -     { -         intCurrentnum=array[i];//Record the cards you currently need to insert -         intj=i-1; +          while(j>=0&&array[j]>currentnum)//compare with the previously ordered cards -         { +array[j+1]=ARRAY[J];//if it is smaller than the previous card, change position Aj--;//index minus one at         } -array[j+1]=currentnum;//Insert the card into the final position -     } -     return 0; - } -  in intOutPut (intArray[],intN) - { to      for(intI=0; i<n;i++) +     { -cout<<array[i]<<'\ n'; the     } *     return 0; $}

Dick Silk needs to be attacked. Learn C + + and algorithm------Insert sort

Related Article

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.