I need to review my implementation of a Single Linked List (SLL), please use the implementation generic and its Should be able to use extended.
The problem is, when I go to (number n: list)
to be list
a MyLinkedList < Integer & gt;
or MyLinkedList & lt; Double & gt;
, I get an error: "Type mismatch: element type can not be converted from object to number".
It is with me that parts I do not know much about, they are generic and iterator.
Thanks in advance.
import java.util.Iterator; Public category MyLinkedList & lt; T & gt; Otterel & lt; Object & gt; Applies {private node head; Public MyLinkedList () {head = zero; } Add Public Zero (node n) {if (head == blank) {head = n; } And {node node = head; While (node.next! = Null) {node = node.next; } Node = n; }} Public Iterator Itater () {New MyLinkedListIterator (Head); } Public full size () {intrate = 0; MyLinkedListIterator = New MyLinkedListIterator (head); While (this hasNext ()) {it.next (); Retired ++; } Return return; } GetHead public node {return head; }} Category MyLinkedListIterator & lt; T & gt; Iterator {applies to the private node node; Public MyLinkedListIterator (node H) {node = H; } Public MyLinkedListIterator (MyLinkedList & lt; T & gt; l) {This (L. G. Head ()); } Next in Public Boolean () {if (node.next == null) {return false; } And {return true; }} Public Object Next () {return node.next; } Public void () {}}
- You have
Iterable & lt; Object & gt; Instead of
Iterable & lt; T & gt; - If a list is empty then
NullPointerException
will throw. -
MyLinkedListIterator.next ()
does not go to the next item in the list.
Comments
Post a Comment