Commit 9bda828
authored
Prevent is_circular from infinite loop (#179)
This commit refines the is_circular() to use slow and fast pointers
instead of a single pointer iteration. The original approach struggled
to detect mid-list loops without extra storage. The new method
effectively identifies such loops, albeit with a minor increase in
conditional checks, but without requiring additional storage.1 parent 297bb61 commit 9bda828
1 file changed
+8
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
875 | 875 | | |
876 | 876 | | |
877 | 877 | | |
| 878 | + | |
878 | 879 | | |
879 | | - | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
880 | 883 | | |
881 | 884 | | |
| 885 | + | |
882 | 886 | | |
883 | 887 | | |
884 | 888 | | |
| 889 | + | |
885 | 890 | | |
886 | | - | |
| 891 | + | |
887 | 892 | | |
888 | 893 | | |
| 894 | + | |
889 | 895 | | |
890 | 896 | | |
891 | 897 | | |
| |||
0 commit comments