Doubly-Link List?

From: D. Beckham (lekhanh88_at_earthlink.net)
Date: 05/30/04


Date: Sun, 30 May 2004 21:38:35 GMT

I wrote the following code to create a short doubly-link list of three
strings: "one", "two", and "three". I would like to know if I set them up
correctly, so that they point to one another.

DLLNode class has already been created. Basically, "one" is the head node,
"two" is the mid node, and "three" is the tail or the last node. I would
like to know if my algorithm for setting up doubly-linked node are correct
before I proceed to printing them. Can anybody give me comments regarding
my algorithm?

public class TestNode
{
 private static DLLNode head = null;
 private static DLLNode tail = null;
 private static DLLNode index = null;

 public static void main(String[] args)
 {
  DLLNode node = new DLLNode("One", null, head);
  if (head == null) //list empty
  {
    head = tail = index = node;
    return;
  }
  head.setPrev(node);
  head = node;

  DLLNode node1 = new DLLNode ("Two");
  index.setNext(node1);
  index.setPrev(head);
  index = node1;

  DLLNode node2 = new DLLNode("Three", tail, null);
  tail.setNext(node2);
  tail.setPrev(node1);
  tail = node2;

   }
}