I'm trying to create a reference based linked list anyone would be able to provide me an example of it??
Asked
Active
Viewed 3,039 times
1
-
See [How do I implement a Linked List in Java?](http://stackoverflow.com/questions/10042/how-do-i-implement-a-linked-list-in-java). In Java, all linked lists are reference-based. – Matthew Flaschen Jun 05 '10 at 10:25
-
@Gabriel Yes it is a homework indeed.... @Matthew Thanks for your help!! – Max Jun 05 '10 at 10:30
-
Double or simple link? This shouldn't be too hard to do by yourself. What you need is an element class to form a basic container with one reference to an Object and other references that can be used for linking. – James P. Jun 05 '10 at 10:53
1 Answers
2
This isn't an answer as such but the following domain class should get you started:
public class Element{
private Object objectLink;
private Element nextElement;
private Element previousElement;
// Getter and setter methods here
}
What you need to add to this is a class that allows adding, removal and checking the state of the list (empty, size, etc.).

James P.
- 19,313
- 27
- 97
- 155
-
I've created a linked list with this. public LinkedList
list = new LinkedList – Max Jun 06 '10 at 02:49(); Does it still require heads or iterator sort of things in order to create a linked list?? -
Well, it depends on whether you are required to implement the full List interface http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html or if what is asked is to create something that fits this description http://en.wikipedia.org/wiki/Linked_list – James P. Jun 06 '10 at 10:07