Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upadditon of integers using LL #2370
Conversation
TravisBuddy
commented
Aug 29, 2020
|
Hey @csendranshi, TravisCI finished with status TravisBuddy Request Identifier: d4a6c320-ea0b-11ea-9476-dd4d5d152bb6 |
|
Cool! Our linter is a bit picky about code style. The easiest way to fix these issues is:
|
|
Thanks for the guidance! I have executed the instructions. |
| self.head = None | ||
|
|
||
| # method to print the linked list | ||
| def printLL(self): |
This comment has been minimized.
This comment has been minimized.
cclauss
Aug 29, 2020
•
Member
It is more Pythonic to define a .__str__() method that returns a str then then we can do print(my_linked_list).
|
|
||
| # node definition | ||
| class Node: | ||
| def __init__(self, data): |
This comment has been minimized.
This comment has been minimized.
cclauss
Aug 29, 2020
Member
Please add Python type hints for function parameters as discussed in CONTRIBUTING.md.
| temp = temp.next | ||
|
|
||
| # method to push a new node onto the linked list | ||
| def push(self, newdata): |
This comment has been minimized.
This comment has been minimized.
cclauss
Aug 29, 2020
Member
Please add Python doctests for .push() and .add() as discussed in CONTRIBUTING.md.
TravisBuddy
commented
Sep 2, 2020
|
Hey @csendranshi, TravisCI finished with status TravisBuddy Request Identifier: 42c8ab60-ed2d-11ea-b6ba-27fe84eba218 |
TravisBuddy
commented
Sep 2, 2020
|
Hey @csendranshi, TravisCI finished with status TravisBuddy Request Identifier: 90e85d40-ed2d-11ea-b6ba-27fe84eba218 |
| """ | ||
| >>> llist.push(9) | ||
| >>> llist.push(9) | ||
| >>> llist.push(9) |
This comment has been minimized.
This comment has been minimized.
cclauss
Sep 2, 2020
Member
So this test shows that we can call LL.push() but it does not really prove that LL.push() did what we expected it to do. How can we have a test that proves that 9 is in the linked list twice?
Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: Christian Clauss <[email protected]>
TravisBuddy
commented
Sep 2, 2020
|
Hey @csendranshi, TravisCI finished with status TravisBuddy Request Identifier: cd712530-ed37-11ea-b6ba-27fe84eba218 |
|
|
||
|
|
||
| # linkedlist definition | ||
| class LL: |
This comment has been minimized.
This comment has been minimized.
| def __str__(self) -> str: | ||
| temp = self.head | ||
| while temp: | ||
| print(temp.data, end=" ") |
This comment has been minimized.
This comment has been minimized.
cclauss
Sep 2, 2020
Member
Line 23 promises that this function will return a str instead of printing the str.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: Christian Clauss <[email protected]>
TravisBuddy
commented
Sep 2, 2020
|
Hey @csendranshi, TravisCI finished with status TravisBuddy Request Identifier: c89a8720-ed48-11ea-b6ba-27fe84eba218 |
| sums = ( | ||
| temp1.data + temp2.data + carry[-1] | ||
| ) # adding the latest element appended to the carry list | ||
| if sums >= 0 and sums <= 9: |
This comment has been minimized.
This comment has been minimized.
TravisBuddy
commented
Sep 2, 2020
Travis tests have failedHey @csendranshi, TravisBuddy Request Identifier: 0e85dce0-ed4d-11ea-b6ba-27fe84eba218 |
|
@csendranshi Build log says
The constructor of def __init__(self):
self.head = Nonetakes no parameters, but you supplied a parameter to it with Correct use would be like what you did on lines 80, 81, 82: llist = LL() # linkedlist 1 |
csendranshi commentedAug 29, 2020
•
edited
Describe your change:
Adding two integers of same length using Linked lists
Example add 321 + 248 = 569
(1)->(2)->(3) + (8)->(4)->(2) = (5)->(6)->(9)
Checklist:
Fixes: #{$ISSUE_NO}.