I used LinkedList as a dymanic array then this array contains strings that need to be sorted in alphabetical order by using merge sort algorithm, which is added in the method and it turned out not working. Any suggestions?
public static LinkedList<String> merge(LinkedList<String> linkedList, LinkedList<String> linkedList2) {
LinkedList<String> result = new LinkedList<String>();
if(linkedList.size() == 0)
result.add(linkedList2.remove());
else if (linkedList2.size() == 0)
result.add(linkedList.remove());
for(int i=0; i<linkedList.size(); i++) {
if(linkedList.get(i).compareTo(linkedList2.get(i)) < 0)
result = linkedList;
else
result = linkedList2;
}
return result;
}