Uh oh!
There was an error while loading. Please reload this page.
Updated singly_linked_list - #2477
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| class LinkedList: | ||
| def __init__(self): | ||
| self.head = None # initialize head to None | ||
| self.size = 0 # length of linked list |
There was a problem hiding this comment.
I am not a fan of this change. This creates duplicate state and opens us up to too many locations where this variable must be accurately updated or we have bugs that are difficult to debug.
Instead, please consider creating an .__iter__() method. Then .__len__() becomes return len(tuple(self)). This could also simplify other methods like .__repr__(), .__str__(), etc.
There are examples of creating this method elsewhere in this repo.
There was a problem hiding this comment.
Can you please give me an example file link in this repo.
There was a problem hiding this comment.
There was a problem hiding this comment.
def__iter__(self):
node=self.headwhilenode:
yieldnode.datanode=node.nextThere was a problem hiding this comment.
add this add source file ?
There was a problem hiding this comment.
Maybe it is just me but I like to sort the .__xxx__() methods above the other methods so the reader knows the builtin capabilities before reading the custom methods.
There was a problem hiding this comment.
Could you please clone this this branch and commit what you want. I am not similar to implement __iter__ . Thanks in advance.
This will break tests, etc.
TravisBuddy
commented
Sep 25, 2020
Travis tests have failedHey @shellhub, TravisBuddy Request Identifier: 9f1dd860-ff19-11ea-b444-3dcc0bd866ab |
TravisBuddy
commented
Sep 25, 2020
Travis tests have failedHey @shellhub, TravisBuddy Request Identifier: 56144e80-ff1c-11ea-b444-3dcc0bd866ab |
realDuYuanChao
commented
Sep 25, 2020
@cclauss It seems build successful. But one Travic CI in Queued. Not running. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| def __getitem__(self, index): | ||
| """ | ||
| Indexing Support. Used to get a node at particular position |
| # Used to change the data of a particular node | ||
| def __setitem__(self, index, data): | ||
| current = self.head |
There was a problem hiding this comment.
Do you mean we need add doctests here ?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* Updated singly_linked_list
* fixup! Format Python code with psf/black push
* undo __repr__
* updating DIRECTORY.md
* UNTESTED CHANGES: Add an .__iter__() method.
This will break tests, etc.
* fixup! Format Python code with psf/black push
* len(tuple(iter(self)))
* fixed __repr__()
* Update data_structures/linked_list/singly_linked_list.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update data_structures/linked_list/singly_linked_list.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update data_structures/linked_list/singly_linked_list.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update data_structures/linked_list/singly_linked_list.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update data_structures/linked_list/singly_linked_list.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update data_structures/linked_list/singly_linked_list.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update data_structures/linked_list/singly_linked_list.py
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.