jeudi 26 janvier 2017

Can a cycle exist in an std::forward_list?

I'm studying Floyd's Tortoise and Hare algorithm, and trying to model the problem using an std::forward_list. Specifically, I'd like to intentionally create a cycle using an std::forward_list, and detect it with said algo.

The "problem" is that this doesn't seem to be possible. I've looked at the constructors and mutator methods. As far as I can tell, the interface to std::forward_list prevents such cycles from occurring. This is typically be a good thing, unless you're prepping for an interview, and would like to purposely implement a forward_list with a cycle :^)

Is it possible to create a cycle in an std::forward_list?

References:

How to detect a loop in a linked list?
http://ift.tt/YpnXEj
http://ift.tt/Z0cztl

Aucun commentaire:

Enregistrer un commentaire