Advertisement
Guest User

recursive insertion

a guest
May 20th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. template <class T>
  2. void ArrayClass<T>::insertionSort(int insertindex) //x to be passed in as 0
  3. {
  4. if (insertindex == usersize - 1 || insertindex == -1) //account of off by one error when reaching the maximum size;
  5. {
  6. return;
  7. }
  8. else
  9. {
  10. int i = insertindex; //i is used to keep of the element that is being compared with every value prior to it 'j';
  11. int j = i;
  12. if (myarr[j] < myarr[i + 1])
  13. {
  14. swapPosition(j, i + 1);
  15. showArray();
  16. i--;
  17. insertionSort(i);
  18. }
  19. //showArray();
  20. insertionSort(insertindex + 1);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement