what is the different between Single List and List Node?

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!!

3

2 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(); } } 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like