DoublyLinkedList Class
Coddy의 이중 연결 리스트 - 자료구조 시리즈 #6 코스 레슨 — 14개 중 4번째.
챌린지
쉬움입력을 받지 않는 생성자를 포함하는 DoublyLinkedList 클래스를 작성하세요.
다음 세 개의 필드를 초기화하세요:
head를null로 설정합니다.tail을null로 설정합니다.count를 0으로 설정합니다.
이전 레슨에서 작성한 Node 클래스를 DoublyLinkedList 위에 유지하세요.
직접 해보기
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "doublylinkedlist.h"
int main() {
DoublyLinkedList ll;
DoublyLinkedList_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 %s %d\n", ll.head == NULL ? "true" : "false", ll.tail == NULL ? "true" : "false", ll.count);
}
return 0;
}