J정처LAB
정보처리기사 실기
편집복원

2025년 1회 정보처리기사 실기

복원 문항을 학습 가능한 표현으로 정리하고 ITPASSLAB이 답안 기준과 해설을 편집 검수했습니다. 자동 판정과 점수는 학습용 예상 결과입니다.

한 문제씩 풀기문제마다 바로 답과 해설을 확인합니다.
0/20답안 작성
프로그래밍 언어 활용난도 중상

18번 · 주관식 · 5점

다음 C 프로그램의 실행 결과를 쓰시오.

C좌우로 밀어 전체 코드 보기
#include <stdio.h>
#include <stdlib.h>

typedef struct Node {
    int value;
    struct Node *next;
} Node;

Node *push(Node *head, int value) {
    Node *node = malloc(sizeof(Node));
    node->value = value;
    node->next = head;
    return node;
}

Node *move_front(Node *head, int target) {
    if (head == NULL || head->value == target) return head;

    Node *previous = NULL;
    Node *current = head;
    while (current != NULL && current->value != target) {
        previous = current;
        current = current->next;
    }
    if (current != NULL) {
        previous->next = current->next;
        current->next = head;
        head = current;
    }
    return head;
}

int main(void) {
    Node *head = NULL;
    for (int i = 1; i <= 5; i++) head = push(head, i);
    head = move_front(head, 3);

    for (Node *p = head; p != NULL; p = p->next) {
        printf("%d", p->value);
    }
    return 0;
}

답안을 입력하세요

학습기록 준비 중