我有一个任务来创建一个链表并分成两个子列表 ,现在我的代码有错误。如果任何人可以帮助我的代码,我不知道哪里需要改变,因为我改变了一些它给了我更多的错误。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