Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int i;
  6. int a[10];
  7.  
  8. int insertionsort()
  9. {
  10. for (i=1;i<10;i++)
  11. {
  12. int j=i+1;
  13. while (j>1)
  14. {
  15. if (a[j]<a[j-1])
  16. {
  17. int tmp = a[j-1];
  18. a[j-1] = a[j];
  19. a[j] = tmp;
  20. j=i-1;
  21. }
  22. }
  23. }
  24. }
  25.  
  26. int main()
  27. {
  28. cout << "enter numbers between 1 to 10 in any order:" <<endl;
  29. for (i=1;i<11;i++)
  30. {
  31. cin >> a[i];
  32. }
  33. insertionsort();
  34. cout << "sorted:" << endl;
  35. for (i=1;i<11;i++)
  36. {
  37. cout << a[i] << endl;
  38. }
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement