mramine364

gnomeSort

May 21st, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function gnomeSort(tab){
  3.  
  4.     var pos =0;
  5.     while (pos<tab.length){
  6.         if( pos==0 || tab[pos-1]<=tab[pos] )
  7.             pos++;
  8.         else{
  9.             swap( tab, pos, pos-1 );
  10.             pos--;
  11.         }
  12.     }
  13.  
  14.     function swap(t, i, j ){
  15.         var temp = t[i];
  16.         t[i] = t[j];
  17.         t[j] = temp;
  18.     }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment