Menu
Coddy logo textTech

LinkedList Class

Coddy의 연결 리스트 - 자료구조 시리즈 #5 코스 레슨 — 14개 중 4번째.

challenge icon

챌린지

쉬움

입력을 받지 않는 생성자를 가진 LinkedList 클래스를 작성하세요.

다음 두 필드를 초기화하세요:

  • headnull로 설정합니다 (리스트는 비어있는 상태로 시작합니다).
  • count0으로 설정합니다.

이전 레슨에서 작성한 Node 클래스를 그대로 유지하세요.

직접 해보기

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "linkedlist.h"

int main() {
    LinkedList ll;
    LinkedList_init(&ll);
    char line[256];
    while (fgets(line, sizeof(line), stdin)) {
        line[strcspn(line, "\r\n")] = '\0';
        char* cmd = strtok(line, " \t");
        if (!cmd) continue;
        if (strcmp(cmd, "state") == 0) printf("%s %d\n", ll.head == NULL ? "true" : "false", ll.count);
    }
    return 0;
}

연결 리스트 - 자료구조 시리즈 #5의 모든 레슨