我有我的气泡排序算法,它可以正常工作,但我想设置它,以便在最终输出的过程中打印每一行。我已经尝试了一些if
语句和for
循环来打印出每行排序,但我似乎无法得到我想要做的事情。这是我的代码
// If bubble sorting is selected here is the code
if(sortRunner == 1) {
int swap;
for(int i = 0; i < list.length - 1; i++) {
for(int j = 0; j < list.length - i -1; j++){
if(list[j] > list[j+1]){
swap = list[j];
list[j] = list[j+1];
list[j+1] = swap;
}
}
}
System.out.print("\nThe bubble sort from the numbers are: ");
for (int k = 0; k < list.length; k++){
System.out.print(list[k] + " ");
}
System.out.println();
} // End bubble sorting here
答案 0 :(得分:4)
只需将 for(int i = 0; i < list.length - 1; i++) {
for(int j = 0; j < list.length - i -1; j++){
if(list[j] > list[j+1]){
swap = list[j];
list[j] = list[j+1];
list[j+1] = swap;
}
System.out.println(Arrays.toString(list));
}
}
放到您想要的位置
每个步骤后打印行
for(int i = 0; i < list.length - 1; i++) {
for(int j = 0; j < list.length - i -1; j++){
if(list[j] > list[j+1]){
swap = list[j];
list[j] = list[j+1];
list[j+1] = swap;
}
}
System.out.println(Arrays.toString(list));
}
这将在一次迭代后打印实际列表
window.location="";
答案 1 :(得分:0)
{{1}}
答案 2 :(得分:0)
使用单独的功能打印行:
select *
into new_table
from
(select top(1455) * from tbl_patients_problems_to_snomed_buckets_2014
where SnoMedScui not in
(select SnoMedScui from groups_first_round)
order by GroupName)
然后在交换后调用它:
public void printLines (int [] array) {
System.out.print(array[i] + " ");
}