java - Linked List, not adding values properly -


i'm working on assignment implement linkedlist data structure, have code finished except it's not working, input code i'm testing "1,2,3,4,5", "1" being outputted instead of of values.

here's code:

// main method functions private static linkedlist createlinkedlist(int[] values) {     linkedlist list;      list = new linkedlist();     (int = 0; < values.length; i++) {         list.add(values[i]);     }     return list; }  private static void printlist(linkedlist list) {     node currentnode = list.gethead();      while(currentnode != null) {         system.out.println(currentnode.getint());         currentnode = currentnode.getnextnode();     } }  // linkedlist class functions public void add(int value) {     node newnode = new node(value);     node currentnode;      if(head == null) {         head = newnode;     } else {         currentnode = newnode;          while(currentnode.getnextnode() != null) {             currentnode = currentnode.getnextnode();         }         currentnode.setnextnode(newnode);     }     size++; } 

can point out i'm doing wrong? let me know if need other functions added in, thanks.

edit: function shows values being added:

private static void processlinkedlist() {     int[] values = new int[] {1,2,3,4,5};     linkedlist list = createlinkedlist(values);     printlist(list);     system.out.println(list); } 

in add() method,

currentnode = newnode; 

should changed

currentnode = head; 

see if moves forward.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -