파라미터 질문좀 ㅠ
아잉누님
2023.04.01
int count_insertion = 0;void main() {
insertion_sort(list, index[], 10, count_insertion);
printf(%d, count_insertion);
}
void insertion_sort(int list[], int index[], int size, int count) {
int i, j;
int next, next_index;
count = 0;
for(i = 1; i size ; i++) {
next = list[i];
next_index = index[i]; for(j = i-1; j= 0 && next list[j]; j--) { bcount++;/blist[j+1] = list[j];index[j+1] = index[j];}list[j+1] = next; index[j+1] = next_index;
}
}
이렇게하면 계속 0이나와요 ㅠㅠ 프로그램 다 쓰면 복잡할까봐 간단히썼는데요,
count_insertion은 전역변수로 선언했구요,
파라미터로 insertion_sort함수에 넣어서 바꾼횟수를 출력하려고 해서
바꿀때 count++을 했는데요,
이렇게하면 전역변수 count_insertion 값은 안변하나요 ㅠㅠ?
list는 바뀌는데, 왜 count_insertion 변수는 안바뀌는지 ㅠㅠ
-
참이삭
b /b 이건 신경쓰지말아주세요 ㅠ HTML 오류인가봐요; 계속 안바뀌네요;