2017-09-26 12 views
0

リストからカーソルを削除し、以前のCarListNode(またはカーソルが以前にリストの先頭を参照していた場合は先頭)を参照しようとしています。カーソル内の情報を返します。 私のコードはカーソルを正しく削除しません。私のコードの問題は何ですか?ここで二重リンクリストからカーソルを削除する

は私の現在のコードです:

public Fruit removeCursor() throws EndOfListException { 

    if (cursor == null) { 
     throw new EndOfListException(); 

    } else if (cursor.getPrev() == null) { 
     head = cursor.getNext(); 
     cursor.setNext(null); 
     cursor.setPrev(null); 
     cursor = head; 

    } else if (cursor.getNext() == null) { 
     tail = cursor.getPrev(); 
     cursor.setPrev(null); 
     cursor.setNext(null); 
     cursor = tail; 

    } else { 
     cursor.setData(cursor.getNext().getData()); //this isn't a singly linked list 
     cursor.setNext(cursor.getNext().getNext()); 
    } 

    count--; 

    return cursor.getData(); 
} 
+0

あなたの質問は何を? –

+0

深夜に申し訳ありません。カーソルが意図したところで削除されていないので、私のコードで何が間違っているかを尋ねていただけです。 –

+0

*私のコードはカーソルを正しく削除しません。私のコードの問題は何ですか?あなたが言うまで、カーソルが何であるか知っている人 – nullpointer

答えて

0

あなたelse句は、 "カーソルを削除しない" ...

このような何か試してみてください:

else { 
    cursor.getPrev().setNext(cursor.getNext()); 
    cursor.getNext().setPrev(cursor.getPrev()); 
    // You might want to release the cursor's item, EG: 
    cursor = null; 
    cursor = cursor.getNext(); 
} 
関連する問題