Untitled
user_9399873
plain_text
a year ago
943 B
3
Indexable
class NewNode{ int val; NewNode rest; //System.out.println(rest+"rest from NewNode"); NewNode(int x) { val=x; } } class NewSolution{ // create linked list public static NewNode createLinkedList(int[] inputlist) { NewNode testhead=new NewNode(0); System.out.println(testhead+"=testhead before"); NewNode rest1=testhead; System.out.println(testhead+"=testhead after"); System.out.println(rest1+"= rest1"); System.out.println(rest1.rest+"=rest1.rest"); for(int i:inputlist){ System.out.println(i+"=i"); rest1.rest=new NewNode(i); System.out.println(rest1.rest+"rest1.rest from loop before"); System.out.println(rest1.val+"=rest.val before"); rest1=rest1.rest; System.out.println(rest1.rest+"rest1.rest from loop"); System.out.println(rest1.val+"=rest.val after"); System.out.println(rest1+"rest1 from loop"); } return testhead.rest; } public static void main(String args[]) { int[] num1={1,2,3,4,5}; NewNode n1=createLinkedList(num1); }}
Editor is loading...
Leave a Comment