Double linked list...

I have a project that is supposed to read in words from a text file in which every word has a sequence number (2-digit #) in front of it. he program is supposed to take the file and print out the words in order (they are out of order in the file). My problem right now is that on line 24 I know that there needs to be an if statement that checks to see if node is now the new first node and, if so, update the value of list, otherwise update node's neighbor to the left to point to node as its neighbor on the right. The problem is that I'm not sure how to write it. Everytime I have tried to write it, I get an error saying something about incompatible types. If anyone can help me figure this out it would be great!!

Here's all the code I have right now.

publicclass Poem

{

private WordNode list;

private WordNode last;

publicvoid add(Word word)

{

WordNode node =new WordNode(word);

WordNode current;

if(list ==null)

list = last = node;

else

{

current = list;

while(current.next !=null && node.word.getSequence() > current.word.getSequence())

current = current.next;

if(node.word.getSequence() < current.word.getSequence())

{

node.prev = current.prev;

node.next = current;

current.prev = node;

}

else

{

node.next = current.next;

node.prev = current;

current.next = node;

}

}

}

public String toString()

{

String result ="";

WordNode current = list;

while(current.next !=null)

{

result += current.word +" ";

current = current.next;

}

result += current.word +" ";

return result;

}

public String toStringBackwards()

{

String result ="";

//WordNode current = last;

//while(current.prev != null)

//{

//result += current.word + " ";

//current = current.prev;

//}

//result += current.word + " ";

return result;

}

privateclass WordNode

{

public Word word;

public WordNode next;

public WordNode prev;

public WordNode (Word word)

{

this.word = word;

next =null;

prev =null;

}

}

}

publicclass Word

{

private String word;

privateint sequence;

public Word(String newWord)

{

sequence = Integer.parseInt(newWord.substring(0, 2));

word = newWord.substring(2);

}

publicint getSequence()

{

return sequence;

}

public String toString()

{

return word;

}

}

import java.util.Scanner;

import java.io.File;

import java.io.IOException;

publicclass PoemTest

{

publicstaticvoid main (String[] args)throws IOException

{

Scanner scan =new Scanner(new File("numbers.txt"));

Poem poem =new Poem();

while(scan.hasNext())

{

poem.add (new Word(scan.next()));

System.out.println ("\n\nForward" + poem );

System.out.println ("\nBackwards: " + poem.toStringBackwards());

}

System.out.println ("\n\nForward" + poem);

System.out.println ("\nBackwards: " + poem.toStringBackwards());

}

}

Numbers.txt:

07Seven 03Three 08Eight 10Ten 02Two 04Four 06Six 01One 09Nine 05Five

THANKS!!!!!!

[6513 byte] By [itz_just_stitcha] at [2007-11-27 2:46:45]
# 1
I think the if statement should be along these lines:if(node.prev == null)list = node;elseSOMETHING?;
itz_just_stitcha at 2007-7-12 3:15:34 > top of Java-index,Java Essentials,New To Java...