dsa · medium
Circular Linked List Insert/Delete
Implement a circular list with 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 the first x. values() return the list from the current head, one lap.
Deleting the head moves head to the next node.
Methods
CircularList(vals)construct the structureinsertAfter(x, y)insertyafter the firstxdelete(x)delete the firstxvalues()one lap of the ring from the current head
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]]