I have a list of strings that are already in alphabetical order. Here we are just going to assume the user enters the items in alphabetical order.
I have a list of string items in a class and a method where someone can pass in another string object to be inserted into the array.
String[] strings = new Strings[0];
public void add(String a){
//here the current list is resized and we need to add the new item
Strings[] newSizedList = new String[strings.length+1];
//for loop here to copy items over into the new resized array.
}
The issue is, the list is assumed to be in alphabetical order already. What I need to do is insert the passed in string into its correct position in the array while still keeping the other items in alphabetical order.
The restriction is that I do not want to use any sort of "sorting algorith". In other words, I do not want to sort the entire list at once and put it in order.
I would like to keep the item in order that it is in since it is already in order but insert the current item into its respective position in the list.
I cannot use any Collection static methods or Java collection classes static methods
Does anyone know how this can be done?