LinkedList Class
الدرس 4 من 14 في دورة القائمة المرتبطة - سلسلة هياكل البيانات #5 على Coddy.
التحدي
سهلاكتب فئة LinkedList مع constructor لا يستقبل أي مدخلات.
قم بتهيئة حقلين:
headمضبوط علىnull(تبدأ القائمة فارغة).countمضبوط على 0.
احتفظ بفئة 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;
}