我使用 LinkedList 作为动态数组,然后该数组包含需要使用合并排序算法按字母顺序排序的字符串,该算法被添加到方法中,但结果无法正常工作。有什么建议么?
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;
}