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