You need to sign in or sign up before continuing.×
Retired
Doubly Linked List (retired)
Loading description...
Object-oriented Programming
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Description needs serious formatting. It's a huge wall of text that denies any attmempt to read and comprehend it.
Format and separate different parts of the two classes and their methods cleanly.
Wait, what? We have to do stuff to nodes we've just thrown away?
And there are probably a million more requirements that isn't in the descriptions, e.g
pop
should return the node and not its value. You need to specify your full requirements.Needs random tests
You're using the same object throughout all the fixed tests. This means the error propagates from one test to the next, which is very hard to debug.
Test feedback is non-existent with the use of
Test.expect
. Please use something likeTest.assertEquals
.As usual, creating a
Node
class and using aLinkedList
class to hold a bunch of nodes is a bad design practice: it breaks the invariant that any part of aLinkedList
is also aLinkedList
.It also introduces weird and counter-intuitive ways to constructor the class, e.g in the sample code:
So if there's nothing both the head and tail becomes
null
? What happens when there is one element? How is@head
and@tail
updated? Where do they even point to? Not to mention that for some reasons your methods are all accepting nodes and not values as input (this is the most egregious withremove
, by comparing nodes by equality). Nobody designs and uses a data structure like this.In fact, most of the code are specifically checking if head equals to the tail, and if yes, set both of them to
null
. You see, this is why this is a confusing and bad design in general.LinkedList
should be a subclass ofNode
.Needs sample tests
A pretty straightforward and fun kata, but considering its nature, I'd add a default test case for some of the basic functionalities before putting it out of beta.
Edit: Also, I'd recommend changing the remove method to not throw an error if the list is empty, it's basically the same thing as if the node wasn't in the chain, and as such should just do nothing.
Lots of fun! :D Awesome Kata
This was fun, but it wasn't clear to me that
append
andprepend
were actually takingNode
instances rather thandata
values. So, I wrote all of my test scaffolding wrong and scratched my head for a long time when I started failing your tests before realizing that when you passed in a variablenode
toappend
you were passing in an already builtNode
instance rather than something that I should wrap in aNode
instance.Also, your initial
pop
method takes an argument that there is no use for.Yes, I was a little thrown by the node argument to pop() as well.
Dang it, that was a copy/paste mistake...
Good fun, and a fulsome set of tests too. Well done.