2
이 버블 정렬을 시도해 보았습니다. 실행했을 때, 원본과 정렬되지 않은 2 개의 정렬 된 목록을 인쇄 한 다음 실제로 정렬 된 목록을 인쇄합니다. 내가? 여분의 '종류'의 어떻게 제거 할 수내 정렬이 왜 여러 목록을 출력합니까?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 9
int main(void)
{
int ray[SIZE]= {8,1,5,8,1,2,4,5,9};
int i, temp, swapped;
for(i = 0; i < SIZE; i++){
ray[i] ;
}
printf("Red ID\n", ray[i]);
for(i = 0; i < SIZE; i++){
printf(" %d\n", ray[i]);
}
while(1){
swapped = 0; // when swapped = 1, loop repeats, when 0, it ends
for(i=0; i<SIZE-1; i++){ //the -1 ends it at the second to last digit in the array
if(ray[i] > ray[i + 1]){
temp = ray[i];
ray[i] = ray[i + 1]; // this whole block does the swapping
ray[i + 1] = temp;
swapped=1;
}
}
if(swapped==0){
break;
}
printf("\n Sorted Red ID\n");
for(i=0; i<SIZE; i++){
printf(" %d\n", ray[i]);
}
}
return 0;
}
'선 [내가].?' –
그리고 당신은 루프 *에서 인쇄 *을, 어쩌면 당신은 외부 * 그렇게해야 * 루프? –
이것은 아무것도하지 않습니다. for (i = 0; i
user3629249