Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Comparable[] shakerSort(Comparable[] array) {
- startTime=System.nanoTime();
- int countOfComp = 0;
- int countOfRewr = 0;
- int size = array.length;
- copy(array);
- boolean swapped;
- do{
- swapped=false;
- for(int i=0;i<=tab.length-2;i++){
- countOfComp++;
- if (comparator.compare(tab[i], tab[i+1]) > 0){
- Comparable temp=tab[i];
- tab[i]=tab[i+1];
- tab[i+1]=temp;
- swapped=true;
- countOfRewr++;
- }
- }
- if(!swapped){
- break;
- }
- swapped=false;
- for(int i=tab.length-2;i>=0;i--){
- countOfComp++;
- if(comparator.compare(tab[i],tab[i+1])>0){
- Comparable temp= tab[i];
- tab[i]=tab[i+1];
- tab[i+1]=temp;
- swapped=true;
- countOfRewr++;
- }
- }
- }while(swapped);
- stopTime=System.nanoTime();
- time=stopTime-startTime;
- System.out.println("SHAKER SORT:");
- System.out.println("liczba porównań: "+countOfComp);
- System.out.println("liczba przepisań: "+countOfRewr);
- System.out.println("czas operacji: "+ time);
- return tab;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement