Results 1 to 3 of 3
Thread: Problem with LinkedList Java
- 07-16-2007, 04:38 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 26
- Rep Power
- 0
Problem with LinkedList Java
I have 2 lists linkedlist and linkedlist2.
I want to be able to take out the first Card out of linkedlist (which starts at 0) and add it to linkedlist2. Then once that is done i want to remove Card 0 from linkedlist, and i want to be able to do this for as many times as i assign to the integer n.
however the part that i bolded doesn't work so how do i do it?
ThanksJava Code:public Deck split(int n) { //implement LinkedList<Card> linkedlist= new LinkedList<Card>(); LinkedList<Card> linkedlist2= new LinkedList<Card>(); int i = n; while (i > 0){ linkedlist2.add(linklist<0>); linkedlist.remove(0); i--;}
- 07-16-2007, 04:43 PM #2
Which bold part?
- 08-07-2007, 04:57 AM #3
Member
- Join Date
- Jul 2007
- Posts
- 39
- Rep Power
- 0
Gox is right:
You could also change it toJava Code:public Deck split(int n) { //implement LinkedList<Card> linkedlist= new LinkedList<Card>(); LinkedList<Card> linkedlist2= new LinkedList<Card>(); int i = n; while (i > 0){ linkedlist2.add(linkedlist.get(0)); linkedlist.remove(0); i--; }
There are a whole bunch of different ways to do it so I suggest looking at the APIJava Code:linkedlist2.add(linkedlist.poll());
Similar Threads
-
Making a stack from a LinkedList
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:28 PM -
Please help me with LinkedList in Java
By lenny in forum New To JavaReplies: 2Last Post: 07-31-2007, 02:24 PM -
how to use LinkedList
By fred in forum Advanced JavaReplies: 1Last Post: 07-24-2007, 01:52 AM -
Problem with LinkedList
By Eric in forum Advanced JavaReplies: 1Last Post: 07-05-2007, 06:08 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks