Advertisement
Wojtekd

Sortowanie babelkowe [Tablice,Funkcje]

Jan 12th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. void swap(double* a, double* b)
  2. {
  3.     double pomoc = *a;
  4.     *a = *b;
  5.     *b = pomoc;
  6. }
  7. void babelkowe(double* t)
  8. {
  9.     int i,j;
  10.     for(i = 0; i < N - 1; i++)
  11.     {
  12.         for(j = 0; j < N - 1; j++)
  13.         {
  14.             if(t[j] > t[j+1])
  15.             {
  16.                 swap(&t[j],&t[j+1]);
  17.             }
  18.         }
  19.     }
  20. }
  21. // bez neipotrzevnych przebiegow petli
  22. void bubbleSort(double* t)
  23. {
  24.     int c,d;
  25.      for (c = 0 ; c < ( N - 1 ); c++)
  26.       {
  27.         for (d = 0 ; d < N - c - 1; d++)
  28.         {
  29.           if (t[d] > t[d+1])
  30.           {
  31.             swap(&t[d],&t[d+1]);
  32.           }
  33.         }
  34.       }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement