public function testListAll()
 {
     $firstData = $this->generateData();
     $secondData = $this->generateData();
     $this->doubleLinkedList->push($firstData);
     $this->doubleLinkedList->push($secondData);
     $dataArray = [$firstData, $secondData];
     $this->assertTrue($this->doubleLinkedList->listAll() == $dataArray);
 }
Esempio n. 2
0
 /**
  *
  */
 public function testInsertionSort()
 {
     $start = microtime();
     $this->sortable->insertionSort($this->doubleLinkedList);
     self::assertEquals($this->doubleLinkedList->listAll(), $this->sorted);
     $end = microtime();
     echo "\n" . "Insertion Sort: " . ($end - $start);
 }
Esempio n. 3
0
 /**
  * @param DoubleLinkedList $list
  */
 public function insertionSort(DoubleLinkedList $list)
 {
     $current = $list->getBottom();
     while ($current) {
         $selectedToCompare = $current->getNext();
         while ($selectedToCompare) {
             if ($current->getData() > $selectedToCompare->getData()) {
                 $this->swap($selectedToCompare, $current);
             }
             $selectedToCompare = $selectedToCompare->getNext();
         }
         $current = $current->getNext();
     }
 }