Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent is_circular function from infinite loop #179

Merged
merged 2 commits into from
Apr 1, 2024

Conversation

wilson20010327
Copy link
Contributor

Original function will face infinite loop when there is a mid-list loop in queue. Transform the is_circular function by shifting from a single pointer approach to employing slow and fast pointers. The single pointer method falls short in detecting loops that occur mid-list without additional storage. Utilizing slow and fast pointers overcomes this limitation, enabling the detection of mid-list loops. Although this approach introduces a slight increase in conditional checks, it remains a superior method for loop detection without the need for extra storage.

Transform the is_circular function by shifting from a single
pointer approach to employing slow and fast pointers. The
single pointer method falls short in detecting loops that
occur mid-list without additional storage. Utilizing slow
and fast pointers overcomes this limitation, enabling
the detection of mid-list loops. Although this approach
introduces a slight increase in conditional checks, it remains
a superior method for loop detection without the need for extra storage.
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summarize your work in the subject of this pull request and associated git commit message. Instead of "Fix," use proper actions such as "Prevent ... from ..."

qtest.c Show resolved Hide resolved
@wilson20010327 wilson20010327 changed the title Fix the is_circular function Prevent is_circular function from infinite loop Mar 28, 2024
To follow the coding style, remove the usless parentheses.
@jserv jserv merged commit 9bda828 into sysprog21:master Apr 1, 2024
1 of 2 checks passed
@jserv
Copy link
Contributor

jserv commented Apr 1, 2024

Thank @wilson20010327 for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants