The Wayback Machine - https://web.archive.org/web/20260217192249/https://github.com/TheAlgorithms/Python/pull/3670
Skip to content

Create detect_n_removeloop.py#3670

Closed
chakirala wants to merge 1 commit intoTheAlgorithms:masterfrom
chakirala:master
Closed

Create detect_n_removeloop.py#3670
chakirala wants to merge 1 commit intoTheAlgorithms:masterfrom
chakirala:master

Conversation

@chakirala
Copy link

@chakirala chakirala commented Oct 23, 2020

Describe your change:

  • 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}.
@chakirala chakirala closed this Oct 23, 2020
@chakirala chakirala reopened this Oct 23, 2020
Comment on lines +84 to +98
# Driver program
llist = LinkedList()
llist.push(10)
llist.push(4)
llist.push(15)
llist.push(20)
llist.push(50)

# Create a loop for testing
llist.head.next.next.next.next.next = llist.head.next.next

llist.detectAndRemoveLoop()

print("Linked List after removing loop")
llist.printList()
Copy link

Choose a reason for hiding this comment

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

Suggested change
# Driver program
llist = LinkedList()
llist.push(10)
llist.push(4)
llist.push(15)
llist.push(20)
llist.push(50)
# Create a loop for testing
llist.head.next.next.next.next.next = llist.head.next.next
llist.detectAndRemoveLoop()
print("Linked List after removing loop")
llist.printList()
if __name__ == "__main__":
# Driver program
llist = LinkedList()
llist.push(10)
llist.push(4)
llist.push(15)
llist.push(20)
llist.push(50)
# Create a loop for testing
llist.head.next.next.next.next.next = llist.head.next.next
llist.detectAndRemoveLoop()
print("Linked List after removing loop")
llist.printList()

You need to run test only when it is run as main and not every time it is imported

self.next = None

class LinkedList:

Copy link

Choose a reason for hiding this comment

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

possibly add a docstring describing about how to use and what does it do, comments are not able to show what is the soul purpose. docstring might help

@ghost
Copy link

ghost commented Oct 23, 2020

Also the tests have failed, (you have checked that you know your pull request would not be merged if tests fail)

@stale
Copy link

stale bot commented Nov 23, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Used to mark an issue or pull request stale. label Nov 23, 2020
@stale
Copy link

stale bot commented Nov 30, 2020

Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions!

@stale stale bot closed this Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Used to mark an issue or pull request stale.

1 participant