+ 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)?

https://code.sololearn.com/c0gxCoA3nd7H/?ref=app

16th May 2022, 12:49 PM
Ame
Ame - avatar
2 ответов
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>
16th May 2022, 1:51 PM
Jayakrishna 🇮🇳
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> {
16th May 2022, 5:44 PM
zemiak