Feeling frustrated with my program I decided to start digging through the jar file that I was given (the one for the linked list game). I finally found the interface for the different methods that I am supposed to implement, as well as some notes on what each objects. This would have been handy from the beginning.
After reading about getHead, I discovered I was supposed to have a dummy head for this linked list. That's not how I'd do it but I suppose it works. After I did that, then read up on insertAfter, I found out I did another thing wrong. Apparently I was supposed to be able to insert a single node or a list of nodes. Not something I'm used to as far as linked list operations go but it's not too hard to include. Another problem I had was the only parameter (besides predecessor) was the node to insert which was called "nodeOrHeadToInsert" which made me think the node could be a head, but after reading the notes on the function it can't be true. I haven't tested it a whole lot so maybe insertAfter does give me the "special head" node. Finally I moved on to fixing my findPredecessor.
The search object was nonintuative, as well as the from. After reading the interface notes, I discovered I was supposed to compare the data with this Object search. Didn't think you could do that since Java is stricktly typed but I managed to shake it a bit to make it work. My line of code came out to be something like this in the end: if(node.getNext().getData().equals(search)). Another problem I had was I had to guess what the "from" parameter was supposed to be for. I eventually figured out that it was supposed to be the point in the list I was searching from. More notes on the "from" variable would be useful.
Apparently node.getNext().getData() == search doesn't bode well with the compiler for one reason or another. Its the first thing that would come to mind for me, but if the compiler doesn't like it I guess I'll have to do it this way.
Once again, using the comments on the interface, I move on to removeNext and removeRemaining. I question the use of "node" on the interface. I'm not sure if using predecessor instead of node would be more useful. Perhaps it might be more intuative. That aside, I got the last two functions working.
With those last two methods complete, the assignment was done. If a student knows what they are doing, the assignment can be done under an hour. For the next step, I'll take the existing instructions then refine them before passing them on.
Note: After playing a little with the program, I was finding that the game never errored when I commented out removeNext. Is that method even needed?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment