Updated and solved the issue in circular_linked_list_list.py#8741
Closed
PranavYewale wants to merge 3 commits intoTheAlgorithms:masterfrom
PranavYewale:master
Closed
Updated and solved the issue in circular_linked_list_list.py#8741PranavYewale wants to merge 3 commits intoTheAlgorithms:masterfrom PranavYewale:master
PranavYewale wants to merge 3 commits intoTheAlgorithms:masterfrom
PranavYewale:master
Conversation
Contributor
|
I'm agree with you that keeping track of the length would give us O(1) time complexity in those operations. Currently in But this idea got rejected in the past. You may want to look at the comments here and here. |
rohan472000
suggested changes
May 20, 2023
Contributor
rohan472000
left a comment
There was a problem hiding this comment.
Look in ruff issue, to fix that use ruff . --fix before pushing.
Contributor
tianyizheng02
left a comment
There was a problem hiding this comment.
Ignoring the arguments for and against having a length attribute, this PR breaks things in other significant ways: removing all imports, removing a required class, removing the test function, and removing the __main__ block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added a length attribute to the CircularLinkedList class to track the length of the linked list.
Updated the len method to return the length attribute instead of calculating the length using a loop. This change improves the space complexity of the len method to O(1).
Updated the insert_tail and insert_head methods to update the length attribute directly instead of calling the len function. This change ensures that the length is accurately maintained.
Updated the insert_nth method to include a check for the index range and raise an IndexError if the index is out of range. This provides better error handling.
Added a delete_tail method that deletes the last node of the linked list. This method calls the delete_nth method with the index set to self.length - 1 and the update_length flag set to True. This ensures that the length is correctly updated when the last node is deleted.
Updated the delete_nth method to include an update_length parameter. When this parameter is set to True, the method will update the length attribute after deleting the node.