私はJavaの実装でキューについて読んでいました。私は、次のタスクを実装する:二重にリンクされたリストの全体リストの順序を逆転
public class DoublyLinkedList
{
private Node first; // the first Node in the list
private Node last; // the last Node in the list
private class Node
{
private Point p;
private Node prev; // the previous Node
private Node next; // the next Node
}
public void reverse()
{
// your code
}
}
私はこのように行った:
public void reverse() { // that reverses the order of the entire list
if (first == null && last == null) {
throw new RuntimeException();
}
Node current = first;
while (current!=null) {
current.next= current.next.prev;
current.prev=current.prev.next;
current=current.next;
}
}
私が右のでしょうか? ありがとう
が期待どおりに仕事を持っているものでしょうか? – dave823
'throw new' ...そこに何かがありません。 – AxelH
https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html – xenteros