Итак, я создал класс, который генерирует обобщенно c двусвязный список. Проблема в том, что файл тестера постоянно говорит, что я что-то сделал неправильно. Похоже, что возникают проблемы с удалением узлов в тесте.
Это удаление тестером.
(Исходные числа 0, 1,2,3,4,5,6,7,8,9 и конечный результат должен быть 1,3,4,5,6,7,8)
public static boolean deleteTest(GenDoubleLinkedList<Integer> intList)
{
printDecorated("Removing Test\nRemoving first item, third item, and last item");
intList.resetCurrent();
intList.deleteCurrent();
intList.goToNext();
intList.deleteCurrent();
while(intList.moreToIterate())
{
intList.goToNext();
}
intList.deleteCurrent();
intList.print();
return valuesMatch(intList,TEST_VALS_2);
}
Эти мои методы deleteCurrent, moreToIterate, resetCurrent и goToNext.
public void deleteCurrent() {
if(current != null && prev != null) {
System.out.println("DELETING " + current.data);
current = current.nextLink;
prev.nextLink = current;
next.prevLink = current;
}
else if(current != null && prev == null) {
System.out.println("DELETING " + current.data);
head = head.nextLink;
current = current.nextLink;
}
}
public boolean moreToIterate() {
//System.out.println(current.nextLink != null);
if(current.nextLink != null)
return true;
return false;
}
public void resetCurrent() {
current = head;
prev = null;
next = current.nextLink;
}
public void goToNext() {
//System.out.println(current.data);
if(current != null) {
current = current.nextLink;
prev = current.prevLink;
next = current.nextLink;
}
}
(у меня есть System.out.println () для устранения неполадок.)
Здесь это то, что выводит консоль.
![enter image description here](https://i.stack.imgur.com/X9FDF.png)
Из моей системы выглядит, что следует удалять правильные узлы, но при запуске теста это явно не удаляло правильные. Я нахожусь в тупике и не могу выяснить проблему.
Если мне нужно, я могу предоставить весь файл тестера вместе с любым моим кодом. Любая помощь приветствуется.