For this program I am dealing with the linkedlist interface. I am designing a method "insert" that will add a new member to a specified location provided by the user (public insert(T newMem, int index) ). Now, I'm not sure how to find the desired index within the list and test whether that index is available to insert the new member. If the list is empty, the new member will be added to the list (should it be added to the head? that just seems confusing to me, because if that member is at index 0 instead of index 7 ... would it be possible to insert the newMember into the desired index of the list? ). Within the final else clause I want to try whether the index is available and if it is empty(), insert the newMember...if it is !empty(), move the member in that index to the tail. Any tips? Is this a good approach?
public void insert(T newMember, int index) { if(empty()){ } else if(index < 0) { System.out.println("Index Out Of Bound"); } else{ try{ member.setData(newMember); }catch(Exception e){ } } }