public static SingleList copy(SingleList list1){ SingleList list2 = new SingleList(); ListNode current=list1.head; while (current != null){ list2.addLast(current.getData()); current=current.getNext(); } return list2; } I do not know what the function of this method or even how it work on computer not even know the difference between node and singlelist!!
32 Answers
ListNode is a node in a linked list. SingleList is a linked list.
To draw an analogy - a node is a link in a chain; the linked list is the chain itself.
ListNode is a node in the linked list and there is some code to better understand the ListNode.
public class List { // return a linked list based on parameters list and soFar public static ListNode process(ListNode list, ListNode soFar) { if (list == null) { return soFar; } else { ListNode temp = list.getNext(); list.setNext(soFar); return process(temp,list); } } // return a new linked list based on parameter n public static ListNode create(int n) { ListNode list = null; for(int k=1; k <= n; k++) { list = new ListNode(new String(""+k), list); } return list; } // print a linked list public static void print(ListNode list) { while (list != null) { System.out.print(list.getValue()+" "); list = list.getNext(); } System.out.println(); } }