我有问题,myStringList.insertLast(name)
我不确定是否需要更改.insertLast
其他内容。该错误表示无法将名称解析为变量。
public class TestLinkedList
{
public static void main(String [] args)
{
// define an Integer linked list MyIntList
LinkedListClass<Integer> MyIntegerList = new LinkedListClass<Integer>();
// intitialize the list
MyIntegerList.initializeList();
// insert a last element 5, then 6, and 7
MyIntegerList.insertLast(5);
MyIntegerList.insertLast(6);
MyIntegerList.insertLast(7);
// print the list
MyIntegerList.print();
// insert first element 8
MyIntegerList.insertFirst(11);
// print the list
MyIntegerList.print();
// define a String linked list MyStringList
LinkedListClass<String> MyStringList = new LinkedListClass<String>();
// initialize the list
MyStringList.initializeList();
// insert last element Chris ,then Tom, and Bo
MyStringList.insertLast(Chris);
MyStringList.insertLast(Tom);
MyStringList.insertLast(Bo);
// print the list
MyStringList.print();
// insert first element Bo
MyStringList.insertFirst(Anna);
// print the list
MyStringList.print();
}
}
我收到的实际错误如下:
4 errors found:
File: C:\Users\GreatOne\Desktop\Master Folder\LinkedList\LinkedList\TestLinkedList.java [line: 36]
Error: Chris cannot be resolved to a variable
File: C:\Users\GreatOne\Desktop\Master Folder\LinkedList\LinkedList\TestLinkedList.java [line: 37]
Error: Tom cannot be resolved to a variable
File: C:\Users\GreatOne\Desktop\Master Folder\LinkedList\LinkedList\TestLinkedList.java [line: 38]
Error: Bo cannot be resolved to a variable
File: C:\Users\GreatOne\Desktop\Master Folder\LinkedList\LinkedList\TestLinkedList.java [line: 44]
Error: Bo cannot be resolved to a variable