Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. public Comparable[] shakerSort(Comparable[] array) {
  2. startTime=System.nanoTime();
  3. int countOfComp = 0;
  4. int countOfRewr = 0;
  5. int size = array.length;
  6. copy(array);
  7. boolean swapped;
  8. do{
  9. swapped=false;
  10. for(int i=0;i<=tab.length-2;i++){
  11. countOfComp++;
  12. if (comparator.compare(tab[i], tab[i+1]) > 0){
  13. Comparable temp=tab[i];
  14. tab[i]=tab[i+1];
  15. tab[i+1]=temp;
  16. swapped=true;
  17. countOfRewr++;
  18. }
  19. }
  20. if(!swapped){
  21. break;
  22. }
  23. swapped=false;
  24. for(int i=tab.length-2;i>=0;i--){
  25. countOfComp++;
  26. if(comparator.compare(tab[i],tab[i+1])>0){
  27. Comparable temp= tab[i];
  28. tab[i]=tab[i+1];
  29. tab[i+1]=temp;
  30. swapped=true;
  31. countOfRewr++;
  32. }
  33. }
  34. }while(swapped);
  35. stopTime=System.nanoTime();
  36. time=stopTime-startTime;
  37. System.out.println("SHAKER SORT:");
  38. System.out.println("liczba porównań: "+countOfComp);
  39. System.out.println("liczba przepisań: "+countOfRewr);
  40. System.out.println("czas operacji: "+ time);
  41. return tab;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement