Guest User

Untitled

a guest
Feb 27th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. template <class elemType>
  2. void insertionSort(elemType list[], int length)
  3. {
  4. for (int firstOutOfOrder = 1; firstOutOfOrder < length;
  5. firstOutOfOrder++)
  6. if (list[firstOutOfOrder] < list[firstOutOfOrder - 1])
  7. {
  8. elemType temp = list[firstOutOfOrder];
  9. int location = firstOutOfOrder;
  10.  
  11. do
  12. {
  13. list[location] = list[location - 1];
  14. location--;
  15. } while(location > 0 && list[location - 1] > temp);
  16.  
  17. list[location] = temp;
  18. }
  19. } //end insertionSort
Advertisement
Add Comment
Please, Sign In to add comment