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

Update doubly_linked_list.py #2573

Closed
wants to merge 12 commits into from

Conversation

akashgkrishnan
Copy link
Contributor

@akashgkrishnan akashgkrishnan commented Oct 1, 2020

Update the implementation of linked list
made changes for optimizing
added more helper methods
used new variable names and function names

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}.

Update the implementation of linked list 
made changes for optimizing
added more helper methods 
used new variable names and function names
@spamegg1
Copy link
Contributor

spamegg1 commented Oct 1, 2020

@Property
def is_empty(self):
def is_empty(self):
return self.head is None
Error: Process completed with exit code 1.

Add a newline at the end of the file.

@akashgkrishnan
Copy link
Contributor Author

can someone help me with why is it getting failed in the pre-commit pull request

@akashgkrishnan
Copy link
Contributor Author

@spamegg1 i have done the same but it still is failing the checks
can you confirm why
and Can you please review the PR and let me know if anything needs to be changed so i can do them as well
Thanks in advance

Updated the complete linked list implementation
@akashgkrishnan
Copy link
Contributor Author

@spamegg1 @dhruvmanila is there something more needs to be done in this PR?

@akashgkrishnan
Copy link
Contributor Author

@cclauss hi sir can you review these changes?



class LinkedList:
"""
Copy link
Member

@cclauss cclauss Oct 15, 2020

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?!?

Copy link
Contributor Author

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:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Member

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)
Copy link
Member

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))?

Copy link
Contributor Author

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
Comment on lines 209 to 211
>>> for value in range(1,10):
... new_linked_list_2.insert(value=value)
>>> print(new_linked_list_2)
Copy link
Member

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
@akashgkrishnan
Copy link
Contributor Author

@cclauss added the suggested testcase

@cclauss
Copy link
Member

cclauss commented Oct 16, 2020

Let's do this. Please change the filename to doubly_linked_list_two.py and we can keep two different implementations of this data structure.

@akashgkrishnan
Copy link
Contributor Author

@cclauss renamed the filename as requested

@cclauss
Copy link
Member

cclauss commented Oct 16, 2020

;-) Let's not delete the current implementation.

@akashgkrishnan
Copy link
Contributor Author

@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
and maintain the existing file as is
since I had updated the same.
cause I had updated the previous file

@cclauss
Copy link
Member

cclauss commented Oct 16, 2020

OK. Can you undelete the dll.py?

@cclauss
Copy link
Member

cclauss commented Oct 16, 2020

If not, then copy dll2 to a new pull request that refers to #2573 and then close this PR.

akashgkrishnan added a commit to akashgkrishnan/Python that referenced this pull request Oct 16, 2020
TheAlgorithms#2573 
the second implementation of the Doubly linked list
@akashgkrishnan
Copy link
Contributor Author

@cclauss new PR created at #3380
closing this PR

cclauss pushed a commit that referenced this pull request Oct 16, 2020
#2573 
the second implementation of the Doubly linked list
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
TheAlgorithms#2573 
the second implementation of the Doubly linked list
peRFectBeliever pushed a commit to peRFectBeliever/Python that referenced this pull request Apr 1, 2021
TheAlgorithms#2573 
the second implementation of the Doubly linked list
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
TheAlgorithms#2573 
the second implementation of the Doubly linked list
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