|
-
October 13th, 2012, 07:08 PM
#5
Re: Double Linked Structure
@OP: Please use the [code][/code] tags to preserve indentation (it will not format unformatted code, though).
Otherwise, people will have a hard time reading your code and understanding your question!
@keang: He's referring to this declaration near the top of the remove() method - the local helper variable "previous":
DoubleNode<T> previous, current;
Basically, the code searches for the node that matches the remove target, simultaneously keeping track of the node it previously tested, so that, later on, it can do this:
previous.setNext(current.getNext());
@OP: Well, If you have a doubly linked list, you can simplify the code, because then the node class would have both getNext() and getPrevious(). Once you've found the target, you can simply do something like this:
DoubleNode<T> previous = current.getPrevious();
previous.setNext(current.getNext()); Or:
current.getPrevious().setNext(current.getNext());
The way you wanted to do it wouldn't work:
contents.setPrevious(contents.getPrevious());
This doesn't change anything. It's saying "set my previous to my current previous"...
Last edited by TheGreatCthulhu; October 13th, 2012 at 07:11 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|