1

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;
        }
    }
}

Error message

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

My main class:

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);
}

error message

G:\LinkedList\src\LinkedTest.java:31: error: cannot find symbol.

myList.splitMid(subList);

symbol: method splitMid(LinkedList)

location: variable myList of type LinkedList

1
  • whats ur meaing about "split into two sublist"??? Commented Oct 19, 2012 at 1:24

2 Answers 2

1

About compilation error:

You are using instance of LinkedList to call the method that you have defined for class UnorderedLinkedList

Sign up to request clarification or add additional context in comments.

Comments

0

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>();

7 Comments

Note that myList will need to be typed as UnorderedLinkedList in order to call splitMid on it.
myList.splitMid(subList); won't compile because myList is statically typed as LinkedList, which doesn't declare splitMid. myList must be declared as UnorderedLinkedList.
Okay cool... subList.size() = 0 won't compile either, sorry.
try to delete subList.count; its not necessary to assign value for count;
try to delete subList.count; its not necessary to assign value for count;
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.