Java Manually convert Array to Node list -


so have following class , trying make method array converted node list. tried loop can't through mind trying set next each value.

public class node {     public node(int value, node link) {         data = value;         next = link;     }      public void setdata(int n) {         data = n;     }      public void setnext(node link) {         next = link;     }      public int getdata() {         return data;     }      public node getnext() {         return next;     }      private int data;     private node next;      public node arraytolist(int[] a) {         (int = 0; < a.length-1; i++) {             node n = new node(a[i], //a[i+1] must node, how loop next node);         }     } } 

just iterate array in reverse order. take care save succ between iterations, , keep n ready final return.

public node arraytolist(int[] a) {   node succ = null;   node n;   (int = a.length-1; >= 0; i--) {     n = new node(a[i], succ );     succ = n;   }   return n; } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -