Guest User

Bubble sortacija by Slay_

a guest
Apr 4th, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.15 KB | None | 0 0
  1. /*
  2.       Bubble sortacija
  3.       http://en.wikipedia.org/wiki/Bubble_sort
  4. */
  5.  
  6. #if defined _sort_included
  7.     #endinput
  8. #endif
  9. #define _sort_included
  10.  
  11. #if !defined _samp_included
  12.     #error "Prvo include-aj a_samp.inc - tek onda include-aj sort.inc"
  13. #endif
  14.  
  15. #define OPERATOR_MALI         (0)
  16. #define OPERATOR_VELIKI       (1)
  17.  
  18. stock sort(niz[], velicina, _OPERATOR_)
  19. {
  20.     new
  21.        bool:zamjenaMjesta = (false),
  22.        iteracija = (0),
  23.        prepisivanje = (0)
  24.     ;
  25.    
  26.     if(_OPERATOR_ != OPERATOR_MALI && _OPERATOR_ != OPERATOR_VELIKI) return \
  27.         print("sort.inc: Pogrešan operator!");
  28.    
  29.     do
  30.     {
  31.         zamjenaMjesta = (false);
  32.         iteracija = (0);
  33.        
  34.         for( ; iteracija < (velicina - 1); ++ iteracija)
  35.         {
  36.             if((_OPERATOR_ == OPERATOR_MALI) && (niz[iteracija] < niz[iteracija + 1])) continue;
  37.             else if((_OPERATOR_ == OPERATOR_VELIKI) && (niz[iteracija] > niz[iteracija + 1])) continue;
  38.            
  39.             prepisivanje = (niz[iteracija]);
  40.             niz[iteracija] = (niz[iteracija + 1]);
  41.             niz[iteracija + 1] = (prepisivanje);
  42.             zamjenaMjesta = (true);
  43.         }
  44.         -- velicina;
  45.     }
  46.     while(zamjenaMjesta != false);
  47.     return (false);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment