我有一個任務來創建一個鏈表並分成兩個子列表 ,現在我的代碼有錯誤。如果任何人可以幫助我的代碼,我不知道哪裏需要改變,因爲我改變了一些它給了我更多的錯誤。Java分割列表
public class UnorderedLinkedList<E extends Comparable<? super E>> extends LinkedList<T>
{
public void splitMid(LinkedList<String> subList)
{
LinkedList<T> current;//the head pointer
LinkedList<T> mid;//the mid point
//Node first = firstNode;
//Node last = firstNode;
//Node subListFirst;
//Node subListLast;
int i;
if(head == null)
{
subList.head = null;
subList.last = null;
subList.count = 0;
}
else
{
//mid =
head = null;
current = head.next;
i = 1;
if(current != null)
current = current.next;
while(current != null)
{
mid = mid.next;
current = current.next;
i++;
if(current != null)
current = current.next;
}
subList.head = head.next;
subList.last = last;
last = mid ;
last.next = null;
subList.count = count - i;
count = i;
}
}
}
錯誤消息
G:\LinkedList\src\LinkedList.java:184: error: cannot find symbol subList.count = 0;
symbol: variable count.
location: variable subList of type LinkedList.Node
where T,E are type-variables:
T extends Object declared in class LinkedList.
E extends Comparable declared in class LinkedList.UnorderedLinkedList
我的主類:
public void main(String args[])
{
LinkedList<Integer> myList = new LinkedList<Integer>();
LinkedList<Integer> subList = new LinkedList<Integer>();
myList.addLast(34);
myList.addLast(65);
myList.addLast(87);
myList.addLast(29);
myList.addLast(12);
myList.splitMid(subList);
}
錯誤信息
G:\LinkedList\src\LinkedTest.java:31: error: cannot find symbol.
myList.splitMid(subList);
symbol: method splitMid(LinkedList)
location: variable myList of type LinkedList
什麼烏爾meaing關於 「分成兩個子列表」 ??? – zetsin