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); }
/** * */ 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); }
/** * @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(); } }