Monday, March 7, 2011

Insertion Sort

int n = 5;
int j, tmp;
int[] A ={5,4,3,2,1};
for (int i= 1 ;i < n; i++)
{
j = i;
tmp = A[i];
while (j>0 && tmp < A[j-1])
{
A[j] = A[j-1];
j = j - 1 ;
}
A[j] = tmp;
}

No comments: