Friday, June 12, 2009

Starting on the Linked List Assignment

My next assignment revolves around the first data structure most computer scientists learn, a linked list. The game, as I understand it, is like Tower of Hanoi except you are supposed to get all the same type of shape in the same column. What the student is supposed to do is to take the empty class of StudentLinkedList and implement the empty methods. If all works well, then the students can play this little game in the end.

My job is to take the existing instructions then refine/add to them. I'm not too sure on what there is to add yet, but I suppose I'll try to think up what to include as I go. I think I may approch this by first doing it myself and writing down a few notes for later just to get an idea of what each function requires, is supposed to do, and to work out any problems I have with the implementation. Then later I will go through a second time to start pulling together instructions for the assignment.

One of the first problems I have encountered is what do I return if the list is empty? For example, on getLast I would figure returning null would be the intuitive action to do if the list was empty, however the linkedlist program gives me an error message telling me I should never do that. Well... What am I supposed to return if there is nothing in the list? Am I to assume that there will always be a head? One that points to either null or a list? Or should I assume head is part of the list?

Ignoring that bit of confusion, I moved on. I first implemented getHead and getLast because they were pretty straight forward. Next I did insertAfter to see if I could tickle the game into at least displaying the objects for the game. Fortunately I managed to do that at least. It still complained about my getLast was returning null. When ever I click on an object on the screen I get this error message: ERROR: Your implementation could not find the selected shape in any linked list. You may have ophaned a link or your findNext method may not be functioning correctly.

I'm given no findNext funciton so I must have an ophand linked. I think that is supposed to be orphaned, not ophaned however. After much fiddling with the code I can't make it be quite. I'll tinker with it later.

No comments:

Post a Comment