• Post Reply Bookmark Topic Watch Topic
  • New Topic

DLL's  RSS feed

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i have a node class like so....




if this is even correct, do i have to have a list driver class?
or can i just link together different node objects?

thx,
Justin.
 
Michael Valentino
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Justin,
I'm not exactly sure what you're trying to do... Could you repost and explain your problem a little bit better? If you're referring to Windows Dynamic Link Libraries... Java doesn't support them. If you're talking about a doubly linked list you can create any List type object (i.e ArrayList, LinkedList) from the java.util package and use a ListIterator to iterate through the list, forward and backward. See the API docs for more information on how to use java.util.List and java.util.ListIterator
Java 5 API Documentation
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok refer to the node class above...



would this work?

that was my question, sorry..

justin...
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you run it?

Is this what you want? Only 4 nodes in the list? That is a bit limited isn't it? A list only needs one explicit class level reference to a node.

You should put several constructors in node, instead of directly setting prev and next. You will also need get and set methods.
 
Michael Valentino
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Justin Fox:




Well, it's the wrong way to do it but, with a few adjustments, this will work....

1) Your constructor can't return anything... don't return int (and the Node references should be Node instead of "node".
2) You don't need getters and setters if your members are public.. as they are in your Node class.

That being said, I MUST say this:
It's a poor implementation of something that is already provided to you by the Java API. It's fine if you want to "tinker" with the language, but if you're actually writing a program to be used anywhere but on your personal machine, this is not the way to do it. Refer to the Java API on Lists and ListIterators. All the work is done for you... you just call the methods. Simple.

Hope that helps
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are implementing your own, i don't think i'd do one, two, three and four. having a reference to each kind of defeats the purpose of having a linked list.

generally, you'd want a node that points to the "front", a node that points to the "back", and then you'd have another you use for traversing the list.

although, now i see your creating a circular list... if you're doing this, then you don't really need a first and a last, you just need a reference to one node, and another to traverse. to traverse the list, you'd start with your moving node at the reference, then next around until they are equal again (and this might be a case where you would use == instead of an .equals() method.).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!