在我的任务中,第三步是调用方法merge来合并list1中的两个列表,以便list1 保持排序.
我编写我的代码,但它不能正常工作,输出显示错误,因为它很重要
public static void merge (ArrayList<Integer> list1, ArrayList<Integer> list2)
{
int i;
int n=list1.size();
int pos , j=0;
for (pos =0 ;pos<n ; pos++)
{
for ( i=0 ; i<n ; i++)
if (list1.get(j)>list2.get(pos))
list1.add(pos,list2.get(pos));
else
j++;
}
}
Run Code Online (Sandbox Code Playgroud)