Closed INotWant closed 4 years ago
The following cases are not considered:
(define l2 (list 1 2)) (set-car! (last-pair l2) l2)
My solution:
(define (have-cycle? x) (define (help x path) (if (not (pair? x)) #f (or (not (false? (memq x path))) (help (car x) (cons x path)) (help (cdr x) (cons x path))))) (help x '()))
sorry, I read the question wrong!
The following cases are not considered:
My solution: