Node
リンクされたリストのノードを表す私のクラスは、次のように定義されています。
public class Node
{
Node next;
String data;
public Node (String data)
{
this.data = data;
}
}
そして、私は次のように使用しています:
Node node, head, tail;
String name; // name to be entered
int count = 0;
// initialize the head to null
head = null;
do
{
System.out.print ("Enter a name. Type q to end.");
name = stdin.readLine ();
// create a new node if the user doesn't type q
if (!name.equals ("q"))
{
node = new Node (name);
node.next = head;
count++;
// update the head to point to the new front of the list
head = node;
}
}
while (!name.equals ("q")); // loop continues until "quit" selected
node = head;
元のリストを変更した場合に備えて、名前をメソッドにバックアップしたいとします。これどうやってするの?ファイルに書き込まずに。
Name はリンクされたリストに保存される変数であり、ユーザーが q を押した後、元のリストをバックトラックまたは表示したい場合に備えて、ユーザーがバックアップとして保存したものを保持しながら、リストを変更したいと考えています。