fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int a[3] = {3, 2, 5};
  5. int s[3] = {0, 0, 0};
  6. int r = 0;
  7. int i;
  8. for(i = 1; i < 3; i++) {
  9. int t = s[r]; // These 2 lines
  10. while((a[i] < a[t]) && (r >= 0)) //
  11. // while((a[i] < a[s[r]]) && (r >= 0)) // instead of this line
  12. {
  13. r--;
  14. }
  15. printf("initialize s[%d] to %d\n", r+1, i);
  16. ++r;
  17. s[r] = i;
  18. }
  19. printf("%d\n", r);
  20. return 0;
  21. }
  22.  
  23.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
initialize s[0] to 1
initialize s[1] to 2
1