You need to sign in or sign up before continuing.×
Retired

Doubly Linked List (retired)

Description
Loading description...
Object-oriented Programming
Algorithms
  • Please sign in or sign up to leave a comment.
  • Voile Avatar

    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.

  • Voile Avatar
    Test remove method ([1,2,4,3,5,6] -> [1,4,3,5,6] -> [4,3,5,6] -> [4,3,5]) 
    
    2 must not have a previous
     
    2 must not have a next
    

    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.

  • Voile Avatar

    Needs random tests

  • Voile Avatar

    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.

  • Voile Avatar

    Test feedback is non-existent with the use of Test.expect. Please use something like Test.assertEquals.

  • Voile Avatar

    As usual, creating a Node class and using a LinkedList class to hold a bunch of nodes is a bad design practice: it breaks the invariant that any part of a LinkedList is also a LinkedList.

    It also introduces weird and counter-intuitive ways to constructor the class, e.g in the sample code:

    constructor: (@head = null) ->
        @tail = @head
    

    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 with remove, 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 of Node.

  • Voile Avatar

    Needs sample tests

  • Zirgion Avatar

    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.

  • xDranik Avatar

    Lots of fun! :D Awesome Kata

  • nklein Avatar

    This was fun, but it wasn't clear to me that append and prepend were actually taking Node instances rather than data 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 variable node to append you were passing in an already built Node instance rather than something that I should wrap in a Node instance.

    Also, your initial pop method takes an argument that there is no use for.

  • JulianNicholls Avatar

    Good fun, and a fulsome set of tests too. Well done.