Results 1 to 2 of 2
- 12-30-2009, 07:34 PM #1Member
- Join Date
- Dec 2009
- Rep Power
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
Last edited by Predz; 12-30-2009 at 08:31 PM.
- 12-31-2009, 02:30 AM #2
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.
- By rocky in forum Web FrameworksReplies: 0Last Post: 04-27-2009, 08:35 PM
- By ravinda in forum New To JavaReplies: 2Last Post: 04-18-2009, 09:16 AM
- By sick_peng in forum New To JavaReplies: 6Last Post: 04-15-2009, 07:33 PM
- By Shivraj in forum New To JavaReplies: 1Last Post: 03-19-2009, 03:30 PM
- By Punter in forum New To JavaReplies: 4Last Post: 02-10-2009, 08:04 AM