我正在与可比较的arraylists合作。我有这些错误: - 语法错误,插入“...... VariableDeclaratorId”完成 FormalParameterList - 方法断点:排序[entry] - mergesort() 这是我的代码,我该怎么办?
import java.util.ArrayList;
import java.util.List;
public class Sorts
{
public ArrayList<Comparable> yay = new ArrayList<Comparable>();
public ArrayList<Comparable> helper = new ArrayList<Comparable>();
public Sorts()
{
}
private void mergesort(List<Comparable> yay, int low, int high)
{
if (low < high)
{
int middle = low + (high - low) / 2;
mergesort(yay, low, middle);
mergesort( yay, middle + 1, high);
merge(low, middle, high);
}
}
private void merge(int low, int middle, int high)
{
for (int i = low; i <= high; i++)
{
helper.set(i,yay.get(i)) ;
}
int i = low;
int j = middle + 1;
int k = low;
while (i <= middle && j <= high)
{
if (helper.get(i).compareTo( helper.get(j))<=0)
{
yay.set(k, helper.get(i));
i++;
}
else
{
yay.set(k, helper.get(j));
j++;
}
k++;
}
while (i <= middle)
{
yay.set(k, helper.get(i));
k++;
i++;
}
}
public static void main(String[] args)
{
ArrayList<Comparable> bla = new ArrayList<Comparable>();
bla.add(2);
bla.add(4);
bla.add(3);
bla.add(1);
Sorts test = new Sorts();
System.out.println(bla);
test.mergesort(bla, 0, 0);
System.out.println("Sorted:");
for(int i=0; i< bla.size();i++)
{
System.out.println(bla.get(i));
}
}
}
答案 0 :(得分:0)
private void mergesort(List<Comparable>)
,您指定了参数类型,但未给它命名,例如:
private void mergesort(List<Comparable> list)