Menu
CoddyTech

DoublyLinkedList 类

Coddy 双向链表:数据结构系列 #6 课程的第 4 课,共 14 课。

challenge icon

挑战

简单

编写一个类 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;
}

双向链表:数据结构系列 #6中的所有课

自己练习: C 在线编译器