Timeline for Double Linked List remove method
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 12, 2014 at 17:17 | history | edited | sha | CC BY-SA 3.0 |
added 125 characters in body
|
Oct 12, 2014 at 17:15 | comment | added | sha | I agree that we better separate search into its own function. As for readability - I think adding comments would solve it. I will update the answer. | |
Oct 12, 2014 at 16:49 | comment | added | tim | oh, but still +1 for this solution. It's pretty much how oracle implemented this. | |
Oct 12, 2014 at 16:45 | comment | added | Aki K | I agree with @tim that your ifs even though they look better they do not convey as well what they are for I think. The separation of the logic though is something that I might do. | |
Oct 12, 2014 at 16:16 | comment | added | tim |
Your simplified checks should work, but I think they are a bit harder to understand (and technically, it's still four cases). I also wouldn't split the method, but if you do, I would do it like this: Change your void remove(T) method to Node<T> search(T) , then add a new remove(T) method which uses search and remove . That way, you can reuse search for other operations (like contains ). Oh, and make all methods containing Node in the signature private, as it shouldn't be exposed.
|
|
Oct 12, 2014 at 15:50 | history | edited | sha | CC BY-SA 3.0 |
added 492 characters in body
|
Oct 12, 2014 at 15:39 | history | answered | sha | CC BY-SA 3.0 |