Joanne
Joanne Neal wrote:In order to insert a value at a specific place in the list you need to use the add(int index, E element) method.
Whilst you could do it using an iterator, a simple for loop and the List.get(int index) method would be better.
And you don't need to check that the list is empty. Get your for loop right and it will handle that condition.
Give it a go and if you have any problems, post your code and tell us what is not working correctly.
Harsha Smith wrote:
Beyond Assignment
Add all elements in the order given by the user.
use Collections.sort(List<T> list>) to sort the elements in ascending order.
use Collections.reverse(List<T> list>) to sort the elements in descending order
Your list has a method for its size, which you can use as your upper bound. You might need two nested loops, one which iterates your inputs and the other which iterates the LinkedList looking for the place to insert it. You would require two tests in the middle of the for loop (the continuation condition).Josh Theisen wrote:. . . . . .
Campbell Ritchie wrote:And are you quite sure it’s i > ??
Josh Theisen wrote:I think maybe I wasn't clear enough with what he wants us to do ... If so, sorry.
.
.
.
With that being said, would a 'for' loop still work? The way I see it we don't know the actual size of the list since
it's being updated in 'real-time' (?)
Joanne
Joanne
Joanne
What a spelling error! That should read log not long.Yesterday, I wrote:Sorting runs in On long n time . . .
Don't get me started about those stupid light bulbs. |