/** * Does not change object's loaded datastructure. * Is a recursive function. * @param DoubleLinkedList $list * @return DoubleLinkedList */ public function mergeSort(DoubleLinkedList $list) { if ($list->count() < 2) { return $list; } $array = $this->split($list); $first = $this->mergeSort($array['firstPart']); $second = $this->mergeSort($array['secondPart']); return $this->merge($first, $second); }