Advertisement
Guest User

Insert sort

a guest
Nov 12th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. srand (time(NULL)) ;
  10.  
  11.  
  12. int t[100];
  13. int i = 0 ;
  14. int x = 0 ;
  15. int y = 0 ;
  16.  
  17. for (i;i<100;i++){
  18. t[i] = (rand()%101) ;
  19. }
  20.  
  21. i = 0 ;
  22.  
  23. while ( i < 100 ){
  24. x = t[i] ;
  25. y = i-1 ;
  26. while ( y >= 0 && t[y] > x ){
  27. t[y+1] = t[y];
  28. y = y-1 ;
  29. }
  30. t[y+1]= x ;
  31. i = i+1 ;
  32. }
  33.  
  34. for (i=0;i<100;i++ ){
  35. cout << t[i]<< "--";
  36.  
  37. }
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement