fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. void Insert(int *S, int k)
  9. {
  10. int key = S[k];
  11. int j = k-1;
  12. while(j>=0 && S[j] > key)
  13. {
  14. S[j+1] = S[j];
  15. j--;
  16. }
  17.  
  18. S[j+1] = key;
  19. }
  20.  
  21.  
  22. void Insertionsort(int S[], int n)
  23. {
  24. if(n>1)
  25. Insertionsort(S,n-1);
  26. Insert(S,n-1);
  27.  
  28. }
  29.  
  30. int main()
  31. {
  32. srand ( time(NULL) );
  33. int S1_8[8];
  34. for(int i=0; i<8; i++)
  35. S1_8[i] = rand()%100;
  36.  
  37. Insertionsort(S1_8,8);
  38.  
  39. for(int i=0; i<8; i++)
  40. {
  41. cout << S1_8[i] << endl;
  42. }
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
15
16
57
67
76
77
87
97