Advertisement
RuiViana

Testa_Sort

Jul 13th, 2016
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. int sortValues[4] = { 50, 150, 40, 80 };
  2. //-------------------------
  3. void setup()
  4. {
  5.   Serial.begin(9600);
  6. }
  7. //------------------------
  8. void loop()
  9. {
  10.   sort(sortValues, 4);
  11.   for (int i = 0; i < 4; i++)
  12.   {
  13.     Serial.print(sortValues[i]);
  14.     Serial.print(",");
  15.   }
  16.   Serial.println(" ");
  17.   delay(500);
  18. }
  19. //----------------------------
  20. void sort(int a[], int size)
  21. {
  22.   for (int i = 0; i < (size - 1); i++)
  23.   {
  24.     for (int o = 0; o < (size - (i + 1)); o++)
  25.     {
  26.       if (a[o] > a[o + 1])
  27.       {
  28.         int t = a[o];
  29.         a[o] = a[o + 1];
  30.         a[o + 1] = t;
  31.       }
  32.     }
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement