Four volunteers from the class will be dealt 13 playing cards (normal deck of 52 cards). Have the students sort their cards from low to high number with 2 being the lowest and ace being the highest card. They should sort their cards without regard to suit. The instructor should not ask them to sort in any particular fashion.
When the players have sorted their cards, ask each volunteer how he/she sorted his/her cards. Some students will probably sort according to insertion sort. The cards in their hand will be in sorted order. They'll pick up a new card and place it in the appropriate position. This placement is similar to the "sliding down" of array elements when using insertion sort on an array of numbers.
The instructor should describe the insertion sort algorithm with code and then perform the algorithm on a hand of cards.
void ins_sort (int b[], int n){
int num; /*currently sorting num*/
int i,j;
for( j = 1; j < n; j++){
num = b[j];
/*insert b[j] into the
sorted sequence at the
appropriate
position*/
i = j - 1;
while (i >= 0 &&
b[i] > num){
b[i + 1] = b[i]; /*move element at b[i]
one position down the array*/
i = i - 1;
}
b[i+1] = num;
}
}