
574 Programming and Data Structures
while(q<num)
{
r°num s[q];
fo r (p «q -l;p > «0 && r<n um s[p];p--)
nums [p+1]=nums[p];
nums [p + 1 ]«r ;
p r i n t f (" Element %d inserted in appropriate place
" # r) ;
p-0;
while (p<xuim)
p rin tf("% d ", nums[p++]);
p rin tf;
q++;
}
p rin tf("S o rt e d elements are: " ) ;
fo r (p « 0; p < num; p++)
p rin tf("% d ", nums[p]) ;
}
OUTPUT;
Enter number of elements: 5
Enter 5 elements: 4 6 2 1 8
Element 6 inserted in appropriate place 4 6 2 1 8
Element 2 inserted in appropriate place 2 4 6 1 8
Element 1 inserted in appropriate place 1 2 4 6 8
Element 8 inserted in appropriate place 1 2 4 6 8
Sorted ...