Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Darla Morrison   on Jul 15 In Java Category.

  
Question Answered By: Dominic Murphy   on Jul 15

Don't think you can get more efficent than what
you've got, if you are doing a "one way"
link.What exactly are you trying to do? It appears that you
are doing a "linked list", but your linked  list only
goes one way. You have no way to find the "previous"
Object.If you have a variable calledLink
previous;Then, have a method:public setPrevious(Link
aPrev){ this.previous = aPrev;}In your
constructor, you would do something like this...public
Link(Object v, link  n){ value  = v; next  = n;
n.setPrevious(this);}Then, you would have a method:public
Link
getPrevious(){ return  this.previous;}Now, you have a
doubly linked list and you can go backward and forward
in the list.Does this help? There's lots
more you can do with the linked list in terms of
sorting, merging, adding things in the list
etc.You can look in the java  Collections Framework to see
some of the Data Structures that are available. They
are the classes in "java.util". The source code
is available when you download the JDK from Sun; and
Sun has some on-line tutorials in using the Java
Collections Framework.

Share: 

 
 
Didn't find what you were looking for? Find more on help with linked Or get search suggestion and latest updates.


Tagged: