私はいくつかのリンクされたリストの質問を解決したいが、私はコンソールからの入力を取ることができない、私は間違っているか分からない。私は私のコードで間違って何をやっているJava(Collectionなし)のSingly/Doubly Linked Listでスキャナを使用してコンソール入力を行う方法は?
:
import java.util.*;
class ScannerInputLinkedList{
static class Node{
int data;
Node next;
}
void insertNode(Node head, int data){
Node curr = head;
Node temp = new Node();
temp.data = data;
temp.next = null;
while(curr.next!=null){
curr = curr.next;
}
curr.next = temp;
System.out.print(curr.data+"->");
}
System.out.println();
public static void main(String[] args) {
ScannerInputLinkedList obj = new ScannerInputLinkedList();
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int x;
Node head = new Node();
while(t-- > 0){
x = sc.nextInt();
obj.insertNode(head, x);
}
}
}
ユーザー入力からリンクリストを作成してそのようなリストをテストするかどうか、少し混乱しますか? – Crabime
は、私はあなたが今までcricket_007 @ 'obj.head' –
を割り当てたとは思わない:それを取得していない、あなたはそれを –