Hi again, all. For class we are now writing our own add method for the linked lists under a class MyLinkedListIterator. Can anyone help point out what it is I am doing wrong? If you need to see more of my code, let me know. Thx.
I'd make a couple of changes. The first is that the exception type doesn't seem to convey the nature of the exception. An IllegalStateException or similar would perhaps be more fitting. The other is that an addBefore method would usually require two arguements. One representing the object to add and the other representing the object to be added before. i.e. as it stands ... add before what ?
Joined: Jul 22, 2002
Here is the add before...
As it stands now, I am having a lot of trouble with references... the program we are using runs a number of test cases, and if you get an error it tells you what you should have. It says I should be getting a number of ints, but instead I am getting memory locations. Our teacher said to do the mod count... to make sure any other methods don't alter it without you knowing or some such... Ah, and here is the actual link part...
As I see it, the addBefore means that it is added before m_current.
With out all of your code its gonna be a guessing game as to what your problem is. Send me your code firstname.lastname@example.org. I'll be happy to take a look at it, when I get a chance. If you could zip all the files together that would be great.
Hi, It seems the problem is in the addBefore(Object o) method of your link class. It seems like you are missing a few lines. Here's what I've come up. I didn't know how to run your tests so i'm not sure if it works. Let me know.
When you are writing this code you have to keep in mind that this is a Doubly linked list. So you have to keep track of m_prev and m_next for all Link objects. Hope this helps.
Joined: Jul 22, 2002
Hmm... that indeed help me on my way! Thanks a lot, to everyone. I really love how the 'community' here helps one another. It seems I wasn't giving enough information to you all, and for that I apologize. The bulk of the problem revolved around the my mis-coding of the previous().... I had put a reference to m_lastReturned when it should have been m_current.m_prev. Then, after fixing the other parts (which was in part thx to people here , I got it running! Thanks again, everyone.