I have an implementation for a problem: Detect Cycle in a Linked List and would like to test it. An online judge for this question is not available on that website.
A correct solution would be to simply return false unconditionally— Box is an exclusive owning pointer, so it’s impossible for you to have any cycles without having already triggered UB. At which point, you can expect your cycle detection code to malfunction anyway.
Box is an exclusive owning pointer, so it’s impossible for you to have any cycles without having already triggered UB. At which point, you can expect your cycle detection code to malfunction anyway.
I don't understand this clearly. Could you elaborate ?
Other questions in this topic have the same structure for ListNode. If I change the structure of ListNode to:
It’s impossible by design to have two Boxes that point to the same memory: Box<T> has essentially the same semantics as holding a T directly, except that it solves some layout problems (i.e. dynamically-sized values and infinite-sized recursive types).