차분히 설명 해주세요.. 코딩 1도 몰라요

이범배88 25-07-23
수정 삭제
정보처리기사 실기 2024년 3회
12. 아래 코드에서 출력되는 값을 작성하시오.
struct Node {
    int value;
    struct Node* next;  
};

void func(struct Node* node) {
    while (node != NULL && node->next != NULL) {
        int t = node->value;
        node->value = node->next->value;
        node->next->value = t;
        node = node->next->next;
    }
}

int main() {
    struct Node n1 = {1, NULL};
    struct Node n2 = {2, NULL};
    struct Node n3 = {3, NULL};
    
    n1.next = &n3;  
    n3.next = &n2;

    func(&n1);

    struct Node* current = &n1;
    while (current != NULL) {
        printf("%d", current->value);  
        current = current->next;
    }
}

왜 답이 312…

null은 뒤에 있는데 왜 안 씀?

1,null이면 next 쓰면 1이 왜 나옴? null나오면 안 됨?

댓글
0 0

모든 문제들의 저작권은 원저작권자에게 있습니다. 본 사이트는 웹상에 공개되어 있는 문제만 모아서 보여드립니다.
저작권 안내   데이터 보호 안내   제휴 문의

copyright 2026 뉴비티::새로운 CBT 시스템 - newbt.kr (Listed on LeanVibe)