fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int a[] = {6,1,3,2,5,4,7};
  5. size_t i, N = sizeof a / sizeof *a;
  6.  
  7. for (i=0; i<N; ++i) printf("%d ", a[i]); puts("\n");
  8.  
  9. while(N > 0)
  10. {
  11. int max = a[0];
  12. for(i = 0; i < N - 1; i++)
  13. {
  14. if(a[i+1] > max)
  15. max = a[i+1];
  16. a[i] = a[i+1] < a[i] ? a[i+1] : a[i];
  17. }
  18. printf("%d ", max);
  19. N--;
  20. }
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 2052KB
stdin
Standard input is empty
stdout
6 1 3 2 5 4 7 

7 4 4 2 2 1 1