Hi, first time posting here!
I need a little help with a uni project im currently doing.
Usually for this sort of thing i'd ask a TA or lecturer but it being the holidays and all, the whole place is shut down and i'd like to get some work done while i have free time.
So, what im trying to do at the moment is create a LinkedList sequence.
Ive coded most of it by modifying an old Vector LinkedList i did but i have to implement a few new methods
The one thats getting me currently is the replaceAtRank(int rank, object element) one.
Im having a total mental block with it.
I can message somebody the work ive done so far if they want to see it but its kinda too big to post here + has multiple files
Well, most linked structures use recursive methods for this type of thing. So, starting at the root node (element), dive into the next node and check it's rank. If the rank is what you're looking for, do this:
Replace a rank 4 with this: (rank 12)
... --->(rank 3)--->(rank 4)--->(rank 7)--->...
Assuming you find that the next element is rank 4 (so we are currently looking at rank 3), set the next link from our rank 12 to rank 7. Do something like:
elementWithRank12.next = elementWithRank3.next.next;
Then set the rank 3 element to point to our rank 12 element
elementWithRank3.next = elementWithRank12;
Leaving you with:
... --->(rank 3)--->(rank 12)--->(rank 7)--->...
Does that make any sense? Tricky to do with text, I can email you a diagram if you want.