Reputation: 25
I have a assignment to create a linked list and split into two sublist and right now I have a error with my code. If any one can help me with my code, I can't figure out where needs to be change every since i change some it gave me more error.
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
Upvotes: 1
Views: 919
Reputation: 303
1.
G:\LinkedList\src\LinkedList.java:184: error: cannot find symbol subList.count = 0;
try to delete subList.count; its not necessary to assign value for count;
2.
G:\LinkedList\src\LinkedTest.java:31: error: cannot find symbol.
myList.splitMid(subList);
do this:
UnorderedLinkedList<Integer> myList = new UnorderedLinkedList<Integer>();
Upvotes: 0
Reputation: 240860
About compilation error:
You are using instance of LinkedList
to call the method that you have defined for class UnorderedLinkedList
Upvotes: 1