我試圖當我嘗試打印輸出不打印任何一個給定的使用插入sort.But數據的排序,適當的輸出是:插入排序調試
Albatross 1
mockingbird 2
vultures 3
redwoodpeckers 6
pigeons 7
crows 10
condos 12
bluejays 15
dodos 15
baldeagles 25
cardinals 40
hummung birds 88
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;
}
可以有人請求幫助
你應該表現出你在哪裏打印陣列的代碼。 – Sumedh
你在哪裏打印?我看不到任何'print'語句 – nachokk
您能提供代碼,您如何調用SortNumericalOrdernsert方法。 –