0

hi
i am new to all this...
right now i am stuck on generic linked lists
i have to create a recursive method to add newnode at end

i have this so far
public static <T> void insert(Node<T> l, Node <T> newNode)

{
if (l == null)
{l = newNode;
}
l.next =
insert(l.next,newNode);


}

the compiler is giving me an error " incompatible types found: void required: Node<T>.... for the line l.next = insert(L.next, newNode)

i am not sure of the syntax... can anyone help me with that

2
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by sufi89
0

According to me the return type of insert should be Node<T> and not only <T>, cause thats what is the type of your "next" member of the Node class.

And next you you post code please make it a point to wrap it inside [code=java] and [/code] tags.

0

<T> is not the return type... it is passing the parameter type since it is generic linked list... return type is void

0

Eep mixed it up during copy paste, but still the return type should be Node<T> rather than "void", cause that is what should be the type of your "next" member of Node class.

0

thanks i think changing the return type helps. it is a textbook problem maybe there was a typo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.