버블소트 왜 정렬인 안되는 걸까요? 도와주세요
안다미로
질문 제목 : 버블소트 왜 정렬인 안되는 걸까요? 도와주세요어디가 틀린 모르겟엉쇼.ㅠㅠ질문 내용 :
#include stdio.h
void bubblesort(int a[], int size)
{
int i, j, temp;
for (i =size-1; i=0; i--) {
for (j = 0; ji; j++) {
if (a[j] a[j+1])
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;
}
}
printf(\npass%d: ,i+1);
for (j=0; j9;j++) {
printf(%2d , a[j]);
}
printf(\n);
printf(학번: 087013, 이름: 이 영재\n);
}
int main(void)
{
int i;
int a[9] = {33,55,77,11,44,88,99,22,66};
printf(정렬 전 배열의 원소\n);
for (i=0; i9; i++)
printf(%2d , a[i]);
printf(\n);
bubblesort(a, 9);
printf(\n정렬 후 배열의 원소\n);
for (i=0; i9; i++)
printf(%2d , a[i]);
printf(\n);
return 0;
}
-
Isolation
근데..이걸 해보면 정렬이 안되어이 있음.ㅜㅜ 뭘 더 추가해야 될까요?????//
저는 일일히 페스과정을 보이고 싶은데... -
밤
if (a[j] a[j+1])
{
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;
} -
튼튼
for (j = 0; ji; j++) {
if (a[j] a[j+1])
}
이렇게 묶으라는 소리 인가요?? -
목화
일단 if문에 들어갈 문장들을 { } 로 묶으세요