我正在处理排序日期的排序双链接列表分配,这是我必须编写的一种方法来测试我的代码。在运行时,我的代码停在
"When searching for the date: 12/10/2023 contains() returns true"
尽管它只是一个system.out.println语句,但应该可以继续。 "包含"我调用的方法只返回一个布尔值。关于为什么我的代码会停止的任何想法?
//in main class
public static void test(SortedLList2<Date> list) {
System.out.println("The list displayed:");
list.display();
System.out.println("The list displayed backwards:");
list.displayBackwards();
int year = list.getEntry(list.getLength() - 1).getYear();
int month = list.getEntry(list.getLength() - 1).getMonth();
int day = list.getEntry(list.getLength() - 1).getDay();
Date newEntry = new Date(month, day, year);
System.out.println("When searching for the date: " + newEntry.toString() + " contains() returns " + list.contains(newEntry));
System.out.println("When removing the date: " + newEntry.toString() + " remove() returns" + list.remove(newEntry));
Date defaultDate = new Date(1, 1, 1000);
System.out.println("When searching for the date: " + defaultDate.toString() + " contains() returns "
+ list.contains(defaultDate));
System.out.println("When trying to remove the date: " + defaultDate.toString() + " remove() returns "
+ list.remove(defaultDate));
System.out.println("The list displayed:");
list.display();
System.out.println("The list displayed backwards:");
list.displayBackwards();
testSortedLList2(list);
}
//in the SortedLList2 class
public boolean contains(T anEntry) {
Node2 currNode = firstDummyNode.getNextNode();
while (currNode != lastDummyNode ) {
if (anEntry.compareTo(currNode.getData()) == 0)
return true;
else
currNode = currNode.getNextNode();
} // end while
return false;
}