-
-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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
Update doubly_linked_list.py #2573
Conversation
Update the implementation of linked list made changes for optimizing added more helper methods used new variable names and function names
removed comments
Add a newline at the end of the file. |
can someone help me with why is it getting failed in the pre-commit pull request |
@spamegg1 i have done the same but it still is failing the checks |
Updated the complete linked list implementation
@spamegg1 @dhruvmanila is there something more needs to be done in this PR? |
@cclauss hi sir can you review these changes? |
|
||
|
||
class LinkedList: | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove all these doctests?!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cclauss I had removed the previous doc test as I had completely changed the implementation. Apologies for that
I have updated the doc test with a set of new test cases and added in much more cases
Kindly review the new changes submitted for the Dubly linked List
Some functions are intentionally made of O(N) time complexity to provide a more user-friendly output on the console.
besides most functions are working in O(1) time complexity
Kindly update in case of furthermore changes are required
New Implementation Added in new doc test cases as per new implementation.
Fixed pre commit fails for PR Added in more test cases deleted the unwanted comments
updated the quotes(pre-commit fail)
Update quotes to fix pre-commit fails
return False | ||
|
||
def get_head_data(self): | ||
if self.head: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.head: | |
return self.head.data if self.head else None |
Same with get_tail_data()
@@ -107,6 +125,8 @@ def delete_value(self, value): | |||
self.tail = self.tail.previous | |||
|
|||
self.remove_node_pointers(node) | |||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function signature does not say that this function returns a string. My sense is that we should raise an exception.
@@ -33,6 +33,24 @@ def __str__(self): | |||
current = current.next | |||
return "<-->".join(str(node) for node in nodes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the "<—>" notation to be a lot of visual clutter. Why not just add an .__iter__()
method and then return str(list(self))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi sir,
I have added in a linked list iterator class for iterating over the linked list
and removed the <--> representation.
However, I have left the str(self) same and just removed the <--> from the string as
this would keep visualizing the linked list if someone wants to visualize the data in the Linked list while debugging as opposed to the memory address that it spits out
I had previously used the <--> representation as I thought it would make the links between nodes more clear
@cclauss I have made the changes
Update Doubly LinkedList created Linked List iterator class Removed the <--> string earlier used to specify link in the linked list added few more getter methods Added type hints
>>> for value in range(1,10): | ||
... new_linked_list_2.insert(value=value) | ||
>>> print(new_linked_list_2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not lose this test! We want a test of a linked list that is longer than one element.
Added in more test cases as requested
@cclauss added the suggested testcase |
Let's do this. Please change the filename to |
doubly_linked_list_two
@cclauss renamed the filename as requested |
;-) Let's not delete the current implementation. |
@cclauss I'm new to this so spare me if I'm being too dumb. but I'm not sure how to rename my implementation to dll2 |
OK. Can you undelete the dll.py? |
If not, then copy dll2 to a new pull request that refers to #2573 and then close this PR. |
TheAlgorithms#2573 the second implementation of the Doubly linked list
#2573 the second implementation of the Doubly linked list
TheAlgorithms#2573 the second implementation of the Doubly linked list
TheAlgorithms#2573 the second implementation of the Doubly linked list
TheAlgorithms#2573 the second implementation of the Doubly linked list
Update the implementation of linked list
made changes for optimizing
added more helper methods
used new variable names and function names
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.