Esempio n. 1
0
 protected function sort(AbstractSort $sort)
 {
     $swapped = TRUE;
     $i = 0;
     $j = $this->length - 1;
     while ($i < $j && $swapped) {
         $swapped = FALSE;
         for ($k = $i; $k < $j; $k++) {
             if ($this->originalData[$k] > $this->originalData[$k + 1]) {
                 ArraysW::swap($this->originalData, $k, $k + 1);
                 $swapped = TRUE;
             }
         }
         $j--;
         if ($swapped) {
             $swapped = FALSE;
             for ($k = $j; $k > $i; $k--) {
                 if ($this->originalData[$k] < $this->originalData[$k - 1]) {
                     ArraysW::swap($this->originalData, $k, $k - 1);
                     $swapped = TRUE;
                 }
             }
         }
         $i++;
     }
     $this->sortedData = $this->originalData;
 }
Esempio n. 2
0
 protected function sort(AbstractSort $sort)
 {
     for ($i = $this->length / 2 - 1; $i >= 0; $i--) {
         $this->repairTop($this->originalData, $this->length - 1, $i);
     }
     for ($i = $this->length - 1; $i > 0; $i--) {
         ArraysW::swap($this->originalData, 0, $i);
         $this->repairTop($this->originalData, $i - 1, 0);
     }
     $this->sortedData = $this->originalData;
 }
Esempio n. 3
0
 protected function sort(AbstractSort $sort)
 {
     $j = $this->length - 2;
     $swapped = TRUE;
     while ($swapped) {
         $swapped = FALSE;
         for ($i = 0; $i <= $j; $i++) {
             if ($this->originalData[$i] > $this->originalData[$i + 1]) {
                 ArraysW::swap($this->originalData, $i, $i + 1);
                 $swapped = TRUE;
             }
         }
     }
     $this->sortedData = $this->originalData;
 }
Esempio n. 4
0
 protected function sort(AbstractSort $sort)
 {
     for ($i = 1; $i < $this->length;) {
         if ($this->originalData[$i - 1] <= $this->originalData[$i]) {
             $i++;
         } else {
             ArraysW::swap($this->originalData, $i, $i - 1);
             $i--;
             if ($i == 0) {
                 $i = 1;
             }
         }
     }
     $this->sortedData = $this->originalData;
 }
Esempio n. 5
0
 protected function sort(AbstractSort $sort)
 {
     for ($i = 0; $i < $this->length - 1; $i++) {
         $min = $i;
         for ($j = $i + 1; $j < $this->length; $j++) {
             if ($this->originalData[$j] > $this->originalData[$min]) {
                 $min = $j;
             }
         }
         if ($min != $i) {
             // this may help
             ArraysW::swap($this->originalData, $i, $min);
         }
     }
     $this->sortedData = $this->originalData;
 }
Esempio n. 6
0
 protected function sort(AbstractSort $sort)
 {
     $swapped = FALSE;
     $gap = $this->length;
     while ($gap != 1 || $swapped) {
         $gap /= 1.33;
         // 4/3
         $swapped = FALSE;
         if ($gap < 1) {
             $gap = 1;
         }
         for ($i = 0; $i + $gap < $this->length; $i++) {
             if ($this->originalData[$i] < $this->originalData[$i + $gap]) {
                 ArraysW::swap($this->originalData, $i, $i + $gap);
                 $swapped = TRUE;
             }
         }
     }
     $this->sortedData = $this->originalData;
 }
Esempio n. 7
0
 protected function sort(AbstractSort $sort)
 {
     for ($i = 0; $i < $this->length / 2; $i++) {
         $swapped = FALSE;
         for ($j = $i; $j < $this->length - $i - 1; $j++) {
             if ($this->originalData[$j] < $this->originalData[$j + 1]) {
                 ArraysW::swap($this->originalData, $j, $j + 1);
                 $swapped = TRUE;
             }
         }
         for ($j = $this->length - 2 - $i; $j > $i; $j--) {
             if ($this->originalData[$j] > $this->originalData[$j - 1]) {
                 ArraysW::swap($this->originalData, $j, $j - 1);
                 $swapped = TRUE;
             }
         }
         if ($swapped) {
             break;
         }
     }
     $this->sortedData = $this->originalData;
 }