The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Question - implement insertAtPosition with the signature

Good afternoon all.

I have just joined these forums, and I thank you for your help in advance.. I was browsing through this forum and it seems to have quite the community for java users, which will be very helpful for me as I have just begun a java orientated class at University.. I am working away through my 4th lab , and have hit a road block, and unfortunately haven't been able to have any classmates help. I was hoping you could point me in the right direction how how I could solve this problem :

Add code to implement insertAtPosition with the signature

public void insertAtPosition(Object what, int insertPosition);

This method inserts the 'what' item at the indicated position. Elements following that position are moved one position in the +1 direction to make room for the new element. Items should only be inserted at already occupied positions, except that it is legal to insert an element at the position just past the filled positions (or at the zero position if there are no items). Note that for a linked list, the elements logically 'move' positions but don't physically move.

Re: Question - implement insertAtPosition with the signature

I am just trying to figure out exactly what it is I am trying to solve with the method.. I am currently drawing out a diagram so I can see what it is I am doing a little better.. So far I know I want to find the element in the linked list before this element,

Set the 'next' pointer of the object being inserted to the object being pointed to by the preceding object, and

Set the 'next' pointer of the preceding object to the object being inserted.

I am going to keep plugging away, if you have any suggestions fell free! Cheers[COLOR="Silver"]