Deletion From A Cyclical List
December 8, 2017
A cyclical list has no beginning and no end; Chez Scheme writes it like this:
#0=(1 2 3 . #0#)
Your task is to write a program that removes an item from a cyclical list; if the item is not present in the cyclical list, it should remain unchanged. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
Here’s a solution in Java.
Output:
I had a bug in my code. I was missing a “break” statement in the remove method. Without this, multiple elements could be removed on a call to remove, whereas my intent was to remove a single element (as indicated in my comment).
Here’s the updated code.