hmm, i don't want to be annoying but...
I'm going to pull all my hair out in about 2 seconds.
I thought I understood Java, but now I'm having second thoughts.
For my data structures class, we are implementing a wrapper linked list class that will work with integers. I understand the logic behind implementing a linked list and dealing with special cases but this is the trouble I'm having:
We have to implement several different methods, for example:
public void addAfter(int x, int newx)
which will add a new element (newx) to this list after the first node containing x. If x does not exist in the list, newx will be added to the end.
My current algorithm has a for loop that traverses the list and searches for x, and then adds the node.
It won't compile though, obviously, because the method doesn't have a pointer to the head of the list you want to search. Maybe I'm missing something incredibly obvious, but I don't understand how this method would ever work without a pointer to the linked list you wish to operate on.
Hopefully someone can help, if something wasn't clear let me know because I'm generally horrible at explaining things. If you want to look at the assignment because my explanation sounds like it came from a flaming idiot, the link is here. Eeep, don't yell at me for breaking community rules, I think my question is specific enough, right?
Oh, and PS - we can't use any methods defined in java's linked list class, this has to be completely coded on our own.
I thought I understood Java, but now I'm having second thoughts.
For my data structures class, we are implementing a wrapper linked list class that will work with integers. I understand the logic behind implementing a linked list and dealing with special cases but this is the trouble I'm having:
We have to implement several different methods, for example:
public void addAfter(int x, int newx)
which will add a new element (newx) to this list after the first node containing x. If x does not exist in the list, newx will be added to the end.
My current algorithm has a for loop that traverses the list and searches for x, and then adds the node.
It won't compile though, obviously, because the method doesn't have a pointer to the head of the list you want to search. Maybe I'm missing something incredibly obvious, but I don't understand how this method would ever work without a pointer to the linked list you wish to operate on.
Hopefully someone can help, if something wasn't clear let me know because I'm generally horrible at explaining things. If you want to look at the assignment because my explanation sounds like it came from a flaming idiot, the link is here. Eeep, don't yell at me for breaking community rules, I think my question is specific enough, right?
Oh, and PS - we can't use any methods defined in java's linked list class, this has to be completely coded on our own.
