Hi I'm working on this new linked list program. Basically what I wanted to do was move all of the data from the linked list into an array, then have the array print out backwards. I was wondering how I would do that. Some one suggested using a loop to me to do that, but I find that method confusing still
This part below that creates the ListNode elements.
To be honest, this seems to be less of a linked list, and more like, some code that manipulate a bunch of nodes that happen to be linked together.
Maybe it would be a good idea to implement the linked list first. Have instances of your linked list class maintain the head, tail, and other needed data. Have methods that can be called to add, insert, and remove elements -- these methods should not expose the node class. Or maybe implement an iterator.
Once you have a fully functioning linked list class, creating a "to array" method should be straightforward.
This is what I have so far. I figure that I still need the cursor part of the program and I probably need to make it an array. What should I do from here?
NOTE: Am I accidentally making the entire linked list one item in the array?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32644
4
posted
0
No. You are accidentally making a 1-element array which you promptly discard.
James Novak
Greenhorn
Joined: Sep 16, 2009
Posts: 10
posted
0
Well how can I change my code to take all of the numbers and turn them into multiple elements.