【发布时间】:2014-02-17 23:30:47
【问题描述】:
我有两个数组,一个是字符串,另一个是整数。 我必须使用插入排序来按数字顺序打印这个列表这是我到目前为止的代码
这些是数组:
String[]bn={"Cardinals","BlueJays","Albatross","Vultures","Crows","Mockingbirds","Condors","BaldEagles","Pigeons","RedHeadWoodPecker","Hummingbirds","Dodos"};
int[]bq={40,15,1,3,10,2,12,25,7,6,88,15};
public static void SortNumericalOrdernsert (String[] bn,int[] bq){
for(int i=1;i<bq.length;i++){
int next=bq[i];
String y=bn[i];
//find all the insertion location
//Move all the larger elements up
int j=i;
while(j>0 && bq[j-1]>next){
bn[j]=bn[j-1];
bq[j]=bq[j-1];
j--;
}
//insert the element
bq[j]=next;
bn[j]=y;
}
}}
我哪里做错了?
【问题讨论】:
-
“必须”是什么意思?这是作业吗?
-
你有什么问题?结果不正确?碰撞?编译错误?
标签: java arrays sorting computer-science