2016-06-21 6 views
-1

。誰かが私を助けることができる?削除Methodeのとノード

private Node remove(Node n){ 

    Node current = first; 
    Node pre=null; 

    w 
    } 
} 
+0

戻り値の型がノードであるため、ノードを返す必要があります。 – theVoid

+0

ヒント:メソッドの最後に 'current!= null'となったらどうなりますか?その場合、メソッドは何を返しますか? – Jesper

答えて

0

あなたはケースをカバーしていないあなたは、ノードが

private Node remove(Node n){ 
    Node current = first; 

    Node pre=null; 

    while(current!=null && !current.equals(n)){ 

     pre=current; 

     current=current.next; 

    } 

if(current==null){ 

    return null; 

} else { 
    //found the node to remove. Connect the pre with the next node, and 
    //return the current node 
} 


} 
0

を削除するために見つけたとき、あなたのメソッドの戻り値の型が型であるノード

private Node remove(Node n) 

の場合あなたは何を返すようにしたい、他の無効 に戻り値の型を変更するには、現在を返しません。ノードを提案する。

if(current==null){ 
     return null; 
    } else { 
     pre.next = current.next; 
     return current; // the node which was remove 
    }