fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <inttypes.h>
  4.  
  5. #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; } while ( 0 )
  6.  
  7. int main(void)
  8. {
  9. int16_t *array_ptr;
  10.  
  11. char n; // true-false
  12. int16_t array[] = { 50, -62, 10, 617, -174, 22, 274, 22, 7, 28, -2888, 16, 6};
  13. int16_t *array_end = &array[sizeof(array)/sizeof(array[0])];
  14. do
  15. {
  16. n=0; // FALSE
  17. array_ptr = array; // SET PTR TO THE BEGIN
  18.  
  19. while (array_ptr != (array_end-1) ) // COMPARE POINTERS
  20. {
  21. if (*array_ptr > *(array_ptr+1)) // COMPARE VALUES
  22. {
  23. SWAP(*array_ptr, *(array_ptr+1)); // SWAP VALUES
  24. n=1; // TRUE
  25. }
  26. array_ptr++;
  27. }
  28.  
  29. }
  30. while (n);
  31.  
  32. array_ptr=array;
  33. while (array_ptr != array_end)
  34. {
  35. printf( "%" PRId16 ", ", *array_ptr++);
  36. }
  37.  
  38. printf("\n");
  39. return 0;
  40. }
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
-2888, -174, -62, 6, 7, 10, 16, 22, 22, 28, 50, 274, 617,