if语句是这样写的
//Check and see if current is less than the next character.
if (node.thisChar().charAt(0) < current.thisChar().charAt(0) )
{
temp = current;
previous = node;
node.next = current;
System.out.println("Its in here");
break;
}// end if
previous = current;
current = current.next;
//what was empty at the end of the list now has a new node being linked.
System.out.println(current.thisChar().charAt(0) + " This is the current");
System.out.println(node.thisChar().charAt(0) + " This is the new character");
System.out.println("Character " + node.thisChar() + " has been added");
问题在于突出显示的 if 语句。例如,如果一个节点字母'd'
小于当前字母'f'
,则 if 语句最终会被跳过,从而产生一个未排序的列表。放置在 if 语句中的输出永远不会到达。奇怪的是我的输出将如何显示字符thisChar().CharAt()
(thisChar
简单地返回字符,它是类型String
);表明这些声明是有效的。除非问题在于变量的类型String
,否则我不知道 if 语句发生了什么。任何建议将被认真考虑。