dsa · medium

Circular Linked List Insert/Delete

GreyOrangeLinked ListDesign

GreyOrange OA: circular list, runtime insert/delete, then print. CircularList(vals) (vals become the ring, head = first). insertAfter(x,y) insert y after the first x. delete(x) delete first x. values return the list from the current head, one lap.

Deleting the head moves head to the next node.

Fill in the CircularList class. The starter already walks ops / args and calls your methods — leave the driver at the bottom as-is. Constructors contribute null; booleans print as true / false.

**Example**

`` CircularList([1,2,3]) → null insertAfter(2, 9) → null values() → [1,2,9,3] delete(1) → null values() → [2,9,3] ``

Constraints

Calls <= 200, values unique in these tests

Examples

Example 1

Input:
["CircularList","insertAfter","values","delete","values"]
[[[1,2,3]],[2,9],[],[1],[]]

Expected:
[null,null,[1,2,9,3],null,[2,9,3]]

Open in the Dojo editor