If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Double Linked Structure

Hello, this code right here needs to take advantage of a doubly linked structure, currently its set up to
a single one, it needs to be without the previous variable and I suspect it should somehow use this .

for exmaple the add method taking advantage I believe looks somewhat like this (although I haven't tested it)

Re: Double Linked Structure

Well this is just a portion of a code, the idea is that the remove method instead of single linked now handles a double link, therefore it no longer needs a previous variable and needs to be able to jump straight from the contents variable to previous and next.

Re: Double Linked Structure

I know this is just a portion of the code but what code is it a portion of? It makes little sense on its own without a full explanation.

I still don't understand what you mean by no longer needing a previous variable. Singly linked structures have a single reference to another node, generally it is a reference to the next node in the structure (although there's no reason you couldn't do one with a previous reference instead), doubly linked structures have both a next and a previous reference hence the name doubly linked. How can you have a doubly linked structure without a previous reference?

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:

Re: Double Linked Structure

Originally Posted by TheGreatCthulhu

@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());

Thanks for pointing that out.
If the OP can't be bothered to use code tags after being asked to do so then I generally don't bother reading their unformatted code.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.