비교할 이력을 최대 2개까지 선택해주세요.
v1 현재
2026-07-01 21:43
수정자: 효동동
문제
아래 C언어 코드에서 출력되는 값을 작성하시오.
지문
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;
}
}
최초 등록 (버전 0)
2024-10-20 20:27
등록자: 상두
문제
아래 코드에서 출력되는 값을 작성하시오.
지문
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;
}
}
자유 댓글