fork download
  1.  
  2. class Node {
  3. public:
  4. Node * next = nullptr;
  5. };
  6.  
  7. template<class TIter>
  8. TIter find(TIter begin) {
  9. auto fast = begin;
  10. auto slow = begin;
  11.  
  12. for (;;) {
  13. fast = fast->next;
  14. if (!fast) break;
  15. fast = fast->next;
  16. if (!fast) break;
  17. slow = slow->next;
  18. }
  19.  
  20. return slow;
  21. }
  22.  
  23. int main() {
  24. Node single;
  25. auto result = find(&single);
  26. return 0;
  27. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty