1
リンクされたリストを時計回りにある量だけ回転したいと思います。リンクされたリストを時計回りに回転する
private class Node {
private T data; // Entry in bag
private Node next; // link to next node
private Node(T dataPortion) {
this(dataPortion, null);
} // end constructor
private Node(T dataPortion, Node nextNode) {
data = dataPortion;
next = nextNode;
} // end constructor
} // end Node
public void leftShift(int num){
if (num == 0) return;
Node current = firstNode;
int count = 1;
while (count < num && current != null)
{
current = current.next;
count++;
}
if (current == null)
return;
Node kthNode = current;
while (current.next != null)
current = current.next;
current.next = firstNode;
firstNode = kthNode.next;
kthNode.next = null;
}
私は反時計回りの回転が仕事を得るために管理が、私は以前のノードを見つけることができませんので、時計回りの回転を取得する方法についてちょっと困惑しています。
私はNodeクラスを続けるだろうと私は、FIFOの実装をListNodeクラスを作成します。次に、私は最後のノードを取るためにキュー()、デキュー()を使用し、キューの先頭に入れます。例を書いてほしい場合は教えてください –
例が参考になります。 – FiftySentos