Code Duplication    Length = 27-27 lines in 2 locations

DataStructures/Lists/CircularLinkedList.php 1 location

@@ 324-350 (lines=27) @@
321
     * @throws OutOfBoundsException if index is negative
322
     *  or is greater than the size of the list.
323
     */
324
    public function delete($index) {
325
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
326
            throw new OutOfBoundsException();
327
        }
328
329
        // if the list is empty
330
        if($this->head === null) {
331
            return null;
332
        }
333
        
334
        // if only there is an element
335
        if($this->head->next === $this->head) {
336
            $temp = $this->head;
337
            $this->head = null;
338
            $this->size--;
339
340
            return $temp->data;
341
        }
342
343
        if($index === 0) {
344
            return $this->deleteBeginning();
345
        } else if($index === $this->size - 1) {
346
            return $this->deleteEnd();
347
        } else {
348
            return $this->deleteAt($index);
349
        }
350
    }
351
352
    /**
353
     * Deletes at the beginnig of the list and returns the data stored.

DataStructures/Lists/DoublyLinkedList.php 1 location

@@ 362-388 (lines=27) @@
359
     * @throws OutOfBoundsException if index is negative
360
     *  or is greater than the size of the list.
361
     */
362
    public function delete($index) {
363
        if($index < 0 || ($index > 0 && $index > $this->size - 1)) {
364
            throw new OutOfBoundsException();
365
        }
366
367
        // if the list is empty
368
        if($this->head === null) {
369
            return null;
370
        }
371
        
372
        // if only there is an element
373
        if($this->head->next === $this->head) {
374
            $temp = $this->head;
375
            $this->head = null;
376
            $this->size--;
377
378
            return $temp->data;
379
        }
380
381
        if($index === 0) {
382
            return $this->deleteBeginning();
383
        } else if($index === $this->size - 1) {
384
            return $this->deleteEnd();
385
        } else {
386
            return $this->deleteAt($index);
387
        }
388
    }
389
390
    /**
391
     * Deletes at the beginnig of the list and returns the data stored.