Menu
Coddy logo textTech

LinkedList Class

Lesson 4 of 14 in Coddy's Linked List - Data Structures Series #5 course.

challenge icon

Challenge

Easy

Write a class LinkedList with a constructor that gets no input.

Initialize two fields:

  • head set to null (the list starts empty).
  • count set to 0.

Keep your Node class from the previous lesson.

Try it yourself

#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;
}

All lessons in Linked List - Data Structures Series #5