|
#include <iostream>
using namespace std;
void InsertSort(int a[],int n)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
int temp;
int j;
for(int i=1;i<n;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(a[i]<a[i-1])
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
temp = a[i];
j = i-1;
do
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
a[j+1] = a[j];
j--;
}while(temp<a[j] && j>=0);
}
a[j+1] = temp;
}
}
int main()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) int r[14] = {10,2,12,3,4,89,5,45,21,7,90,112,78,91};
InsertSort(r,14);
for(int i=0;i<14;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cout<<r[i]<<endl;
}
getchar();
return 0;
}
|