我想用對象實現鏈表。當我編譯代碼時,我得到這個錯誤味精:鏈表和對象問題
Person.java:49: error: constructor Node in class Node cannot be applied to given types;
Node newNode = new Node(last, first, age);
任何人都可以親切地給我一隻手嗎?爲什麼發生這種情況?謝謝。 下面是代碼:
class Person{
private String lastName;
private String firstName;
private int age;
public Person(String last, String first, int a){
lastName=last;
firstName=first;
age=a;
}
public void displayPerson(){
System.out.println("Last Name: "+lastName);
System.out.println("First name"+firstName);
System.out.println("Age: "+age);
}
public String getLast(){
return lastName;
}
}
class Node
{
public Person data;
public Node next;
public Node(Person d)
{
data = d;
}
}
class LinkList
{
private Node first;
public LinkList()
{
first = null;
}
public boolean isEmpty()
{
return (first==null);
}
public void insertFirst(String last, String first, int age)
{
Node newNode = new Node(last, first, age);
newNode.next = first;
first = newNode;
}
public Node deleteFirst(String last, String first, int age)
{
Node temp = first;
first = first.next;
return temp;
}
public void displayList()
{
System.out.print("Linked List (first -->last): ");
Node current = first;
while(current != null)
{
current.displayPerson();
current = current.next;
}
System.out.println(" ");
}
}
你在哪裏有一個節點構造函數,它需要'string,string,int'?另外'first = newNode;'是不明確的,我想你的意思是寫一些像'this.first = newNode;' – tnw