The toString method returns a String containing the items of all the nodes in the list separated by commas. The current version will not work correctly if the list is circular,I need to Fix the method so that it will work correctly for both normal and circular lists. but im struggling with my current code
public String toString(){
String str = "";
Node current = head;
while(current != null){
str = str + current.getItem();
current = current.next();
if (current != null){
str = str + ", ";
}
}
return str;
}