Advertisement
RuiViana

Sort numeros

Jul 13th, 2016
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. int sortValues[13] = { 2, 7, 4, 6, 5, 3, 8, 10, 9, 11, 14, 12, 13 };
  2.  
  3. int str1 = 50;
  4. int str2 = 150;
  5. int str3 = 40;
  6. int str4 = 80;
  7.  
  8. //-------------------------
  9. void setup()
  10. {
  11.   Serial.begin(9600);
  12. }
  13. //------------------------
  14. void loop()
  15. {
  16.   sort(sortValues,13);
  17.  
  18.   Serial.print("Sorted Array: ");
  19.   for(int i=0; i<13; i++)
  20.   {
  21.      Serial.print(sortValues[i]);
  22.      Serial.print(",");
  23.   }
  24.   Serial.println("");
  25.   Serial.print("Max Number: ");
  26.   Serial.print(sortValues[12]);
  27.   Serial.println("");
  28.   Serial.print("Min Number: ");
  29.   Serial.print(sortValues[0]);
  30.   Serial.println("");
  31.  
  32.   delay(10000);
  33. }
  34. //----------------------------
  35. void sort(int a[], int size)
  36. {
  37.     for(int i=0; i<(size-1); i++)
  38.     {
  39.         for(int o=0; o<(size-(i+1)); o++)
  40.         {
  41.                 if(a[o] > a[o+1])
  42.                 {
  43.                     int t = a[o];
  44.                     a[o] = a[o+1];
  45.                     a[o+1] = t;
  46.                 }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement