+ 1
How to insert a string in a circular linked list (i want to check the duplicatewords in the circular linked list from the user)?
2 odpowiedzi
0
You are adding String but your implementation of addFirst() methods expects of type Node<String> type as argument.
So there is mismatch, incompatibles..
I think, Better try to use generics type <T>
0
delete private on Node class:
//private
class Node<String> {
modify add method:
public void addFirst(Node<String> w) {
Node<String> newest = w;
if (tail == null)
tail = newest;
else
tail.next = newest;
newest.next = head;
head = newest;
size++;
}
then add is:
list.addFirst( list.new Node<String>(
"word", null) );
it is curious, because
class LinkedList<String> {
using type parameter named String which is
not java.lang.String type argument but just your name for
variable like T in
class LinkedList<T> {