Tarrell Fletcher wrote:Here's my current code...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Tarrell Fletcher wrote:I need to make a method called getSize() and the method just returns the value of the instance variable you use to keep track of size. But here's the catch....I'm not suppose to traverse the list...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Tarrell Fletcher wrote:I need to make a method called getSize() and the method just returns the value of the instance variable you use to keep track of size. But here's the catch....I'm not suppose to traverse the list...
OK, so how else do you think you might do it? (Tip: the answer is in your instructions, which as far as I can see you haven't followed - at least not yet).
Ok so I just reread it, it seems like it is telling me to make an global counter and then I guess increment it whenever something is added to it. And Im just calling that variable to see where the counter is at. And I guess if I do a remove method to make sure I decrement whenever something is deleted?
Winston
Tarrell Fletcher wrote:Ok so I just reread it, it seems like it is telling me to make an global counter and then I guess increment it whenever something is added to it. And Im just calling that variable to see where the counter is at. And I guess if I do a remove method to make sure I decrement whenever something is deleted?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
That sounds very peculiarTarrell Fletcher wrote: . . . I am to use the comparator in my remove method. But so far does this seem correct? . . .
Apart from your getLast and retrieveLast methods having confusing names, there is some poor style there. Look for a style guide which tells you what to use instead. (Hint: try here.)Campbell Ritchie wrote:
That sounds very peculiarTarrell Fletcher wrote: . . . I am to use the comparator in my remove method. But so far does this seem correct? . . .
Tarrell Fletcher wrote:I'm just trying to see if the remove method seems correct because I am trying to test the methods but I do not know how to pass a comparator as an argument. Ive tried doing like...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Tarrell Fletcher wrote:I'm just trying to see if the remove method seems correct because I am trying to test the methods but I do not know how to pass a comparator as an argument. Ive tried doing like...
And that's most of your problem, I think: You're concentrating too much on coding, when what you need to do is take a step back and understand the problem.
Linked Lists are tricky and fiddly, and can be very hard to visualise when you're just looking at code.
My advice: Turn off your computer and draw some diagrams. A node can be drawn with a simple circle or box and an arrow for the "next" pointer(*). So maybe start out with two of those named 'head' and 'tail' and draw out all the stages needed for an "add first" and "add last", along with written instructions in English. Once you're happy with that, do the same thing for your 'peek' (get()) and 'pop' (retrieve()) methods (those are the "official" names for those functions).
The main thing is to make sure you really know the mechanics before you write another line of Java code; otherwise you're going to spend a lot of time "trying things out".
Winston
(*) - I actually often use a dot and an arrow: a dot on the edge of the box or circle to denote the pointer itself, and an arrow to show when it's actually pointing to something (because it can be null, which means "pointing to nothing").
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|