Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Sort - GnomeSort.java

GnomeSort.java

Caricato da:
Scarica il programma completo

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package sort;
  7.  
  8. /**
  9.  *
  10.  * @author Paolo
  11.  */
  12. public class GnomeSort extends SortMethod{
  13.  
  14.     @Override
  15.     public Integer[] sort(Integer[] pArray) {
  16.         System.out.println("I'm a gnome sort!");
  17.         int i=0;
  18.         int swap=0;
  19.         while(i<pArray.length){
  20.             if(i==0 || pArray[i]>=pArray[i-1]){
  21.                 i++;
  22.             }else{
  23.                 swap=pArray[i];
  24.                 pArray[i]=pArray[i-1];
  25.                 pArray[i-1]=swap;
  26.                 i--;
  27.             }
  28.         }
  29.         return pArray;
  30.     }
  31.  
  32. }