Skip to content

Contains loops.py add#2442

Merged
cclauss merged 9 commits into
TheAlgorithms:masterfrom
kanthuc:contains_loops.py-Add
Sep 18, 2020
Merged

Contains loops.py add#2442
cclauss merged 9 commits into
TheAlgorithms:masterfrom
kanthuc:contains_loops.py-Add

Conversation

@kanthuc
Copy link
Copy Markdown
Contributor

@kanthuc kanthuc commented Sep 17, 2020

Describe your change:

Added an algorithm which checks a linked list for loops and returns true if one is found.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Copy link
Copy Markdown
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

We need at least two doctests. One that returns True and one that returns False. We need to defined what a loop is. Is a loop just the same value twice in a row? Would 1, 2, 1, 2 be a loop?

def contains_loop(root: Node) -> bool:
"""
given a node, returns true if linked list contains a loop
A linked list contains a loop when traversing through a loop, no null is reached.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This explanation is still unclear to me. What is a null in this context?

@TravisBuddy
Copy link
Copy Markdown

Hey @kanthuc,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 500c6ff0-f9e9-11ea-8549-e58e00c6eb1f

@TravisBuddy
Copy link
Copy Markdown

Hey @kanthuc,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 04efb2f0-f9eb-11ea-8549-e58e00c6eb1f

@TravisBuddy
Copy link
Copy Markdown

Travis tests have failed

Hey @kanthuc,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: dde3b520-f9eb-11ea-8549-e58e00c6eb1f

@TravisBuddy
Copy link
Copy Markdown

Travis tests have failed

Hey @kanthuc,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: bffc4d90-f9ed-11ea-8549-e58e00c6eb1f

@TravisBuddy
Copy link
Copy Markdown

Hey @kanthuc,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: c80f7e60-f9ef-11ea-8549-e58e00c6eb1f

@cclauss cclauss merged commit ecac7b0 into TheAlgorithms:master Sep 18, 2020
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* added an algorithm which checks a linked list for loops and returns true if one is found

* added doctests and clarified meaning of loop

* Define Node.__iter__()

* Update and rename has_loop.py to has_duplicate_data.py

* Update has_duplicate_data.py

* Update has_duplicate_data.py

* Update and rename has_duplicate_data.py to has_loop.py

* Update has_loop.py

Co-authored-by: Christian Clauss <cclauss@me.com>
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.

3 participants