Results 1 to 2 of 2
Thread: List only appends one item
- 02-23-2014, 09:16 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 18
- Rep Power
- 0
List only appends one item
Node inside a linkedlist
SomeInterface has anJava Code:addLast()
Java Code:public sizeCount=0; public LinkedList<T> implements SomeInterface<T>{protected class Node<T>{ privateT data; private Node<T> head,tail; protected Node(T data,Node<T>tail){ this.data=data;head=null;this.tail=tail;} private T getInfo(){return this.data;} private void setTail(Node<T>newTail){this.tail=newTail;} private void setLink(Node<T>newHead){this.head=newHead;} private Node<T> getLink(){return tail;} }} public void addLast(){ } }//end of LinkedList<T> class
Java Code:LinkedList<String>somelist=new LinkedList<T>()
Java Code:somelist.append("William");somelist.append("Fredkrick");somelist.append("Maria")
Also, here's theJava Code:append()
Java Code:Node<E>topNode=null; append(E thing){ if(thing==null){throw new InvalidInputException();} else{ if(topNode==null){ topNode=new Node<E>(thing,null); sizeCount++;return this;} if(topNode.tail==null){topNode.tail=new Node<E>(thing,null);return this;} else{topNode=topNode.tail;append(thing);return this;} } }
Last edited by pyler; 02-23-2014 at 11:58 PM.
- 02-23-2014, 09:18 PM #2
Re: List only appends one item
Please edit your post and wrap your code with code tags:
[code]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.
Also the code needs to reformatted. There should only be one statement per line.
There should not be code on the same line as a }If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
unselected item from selected list
By prasathbala in forum NetBeansReplies: 0Last Post: 01-10-2012, 06:41 AM -
How to add item on list
By Aenohe in forum New To JavaReplies: 4Last Post: 12-09-2011, 12:05 AM -
access array list item from draw
By trishtren in forum New To JavaReplies: 8Last Post: 04-19-2011, 01:34 PM -
Appending and item to a Select List
By Samurai Coder in forum New To JavaReplies: 1Last Post: 12-04-2009, 11:56 PM -
Button to remove item from list
By dacool25 in forum Java AppletsReplies: 6Last Post: 10-14-2009, 05:30 AM
Bookmarks