Language: C

#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>

#define UTIL_PRINT_ARRAY(arr, size)                                                                                                        \
  do {                                                                                                                                     \
    int32_t _i;                                                                                                                            \
    for (_i = 0; _i < (size); _i++) {                                                                                                      \
      if (_i != 0) printf(" ");                                                                                                            \
      printf("%d", arr[_i]);                                                                                                               \
    }                                                                                                                                      \
    printf("\n");                                                                                                                          \
  } while (0)

struct double_linked_list_tag {
  double_linked_list_t *prev;
  double_linked_list_t *next;
  int32_t data;
};

typedef struct double_linked_list_tag double_linked_list_t;

double_linked_list_t *double_linked_list_create(void)
{
  double_linked_list_t *l = (double_linked_list_t *)malloc(sizeof(double_linked_list_t));

  if (l == NULL) {
    perror("memory is full\n");
    exit(1);
  }

  l->prev = l;
  l->next = l;

  return l;
}

void double_linked_list_destroy(double_linked_list_t *const l)
{
  if (l == NULL) return;

  double_linked_list_t *list = l->next;

  while (l != list) {
    double_linked_list_t *next = list->next;
    free(list);
    list = next;
  }

  free(l);

  return;
}

bool double_linked_list_insert(double_linked_list_t *const l, int32_t data)
{
  if (l == NULL) return false;

  double_linked_list_t *new = (double_linked_list_t *)malloc(sizeof(double_linked_list_t));

  if (new == NULL) {
    perror("memory is full\n");
    exit(1);
  }

  l->next->prev = new;
  new->next = l->next;
  l->next = new;
  new->prev = l;
  new->data = data;

  return true;
}

static bool check_arguments(double_linked_list_t *const l, int32_t buf[], const size_t size)
{
  if (l == NULL) return false;

  if (size < 1) return false;

  if (buf == NULL) return false;

  return true;
}

size_t double_linked_list_to_array(double_linked_list_t *const l, int32_t buf[], const size_t size)
{
  if (!check_arguments(l, buf, size)) {
    return 0;
  }

  size_t count = 0;

  double_linked_list_t *list = l->next;
  while (list != l) {
    buf[count] = list->data;
    count++;
    if (size <= count) break;
    list = list->next;
  }

  return count;
}

bool double_linked_list_delete(double_linked_list_t *const l, int32_t data)
{
  if (l == NULL) return false;

  double_linked_list_t *list = l->next;

  while (list != l) {
    if (list->data == data) {
      double_linked_list_t *next = list->next;
      double_linked_list_t *prev = list->prev;
      next->prev = list->prev;
      prev->next = list->next;
      free(list);
      return true;
    }
    list = list->next;
  }

  return false;
}

bool double_linked_list_delete_first(double_linked_list_t *const l)
{
  if (l == NULL) return false;

  if (l == l->next) return false;

  double_linked_list_t *head = l->next;
  double_linked_list_t *new_head = head->next;

  l->next = new_head;
  new_head->prev = l;

  free(head);

  return true;
}

bool double_linked_list_delete_last(double_linked_list_t *const l)
{
  if (l == NULL) return false;

  if (l == l->prev) return false;

  double_linked_list_t *last = l->prev;
  double_linked_list_t *new_last = last->prev;

  new_last->next = l;
  l->prev = new_last;

  return true;
}

#if !defined(TEST)
#include <stdio.h>
#include <string.h>

#include "util.h"

int32_t main(void)
{
  double_linked_list_t *l = double_linked_list_create();

  int32_t num = 0;
  scanf("%d", &num);

  int32_t i;
  for (i = 0; i < num; i++) {
    char buf[128];
    int32_t val;
    int32_t ret = scanf("%s %d", buf, &val);
    if (ret == 2) {
      switch (buf[0]) {
      case 'i':
        double_linked_list_insert(l, val);
        break;
      case 'd':
        double_linked_list_delete(l, val);
        break;
      }
    } else {
      if (!strcmp(buf, "deleteFirst")) {
        double_linked_list_delete_first(l);
      } else {
        double_linked_list_delete_last(l);
      }
    }
  }

  int32_t result[1024];
  size_t size = double_linked_list_to_array(l, result, UTIL_ARRAY_SIZE(result));
  UTIL_PRINT_ARRAY(result, size);

  double_linked_list_destroy(l);

  return 0;
}
#endif

Compiler output:
main.c:16:3: error: unknown type name 'double_linked_list_t'
   16 |   double_linked_list_t *prev;
      |   ^~~~~~~~~~~~~~~~~~~~
main.c:17:3: error: unknown type name 'double_linked_list_t'
   17 |   double_linked_list_t *next;
      |   ^~~~~~~~~~~~~~~~~~~~
main.c: In function 'double_linked_list_create':
main.c:28:5: error: implicit declaration of function 'perror' [-Wimplicit-function-declaration]
   28 |     perror("memory is full\n");
      |     ^~~~~~
main.c:32:11: error: assignment to 'int *' from incompatible pointer type 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} [-Wincompatible-pointer-types]
   32 |   l->prev = l;
      |           ^
main.c:33:11: error: assignment to 'int *' from incompatible pointer type 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} [-Wincompatible-pointer-types]
   33 |   l->next = l;
      |           ^
main.c: In function 'double_linked_list_destroy':
main.c:42:32: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
   42 |   double_linked_list_t *list = l->next;
      |                                ^
main.c:45:34: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
   45 |     double_linked_list_t *next = list->next;
      |                                  ^~~~
main.c: In function 'double_linked_list_insert':
main.c:66:10: error: request for member 'prev' in something not a structure or union
   66 |   l->next->prev = new;
      |          ^~
main.c:68:11: error: assignment to 'int *' from incompatible pointer type 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} [-Wincompatible-pointer-types]
   68 |   l->next = new;
      |           ^
main.c:69:13: error: assignment to 'int *' from incompatible pointer type 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} [-Wincompatible-pointer-types]
   69 |   new->prev = l;
      |             ^
main.c: In function 'double_linked_list_to_array':
main.c:94:32: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
   94 |   double_linked_list_t *list = l->next;
      |                                ^
main.c:99:10: error: assignment to 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
   99 |     list = list->next;
      |          ^
main.c: In function 'double_linked_list_delete':
main.c:109:32: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
  109 |   double_linked_list_t *list = l->next;
      |                                ^
main.c:113:36: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
  113 |       double_linked_list_t *next = list->next;
      |                                    ^~~~
main.c:114:36: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
  114 |       double_linked_list_t *prev = list->prev;
      |                                    ^~~~
main.c:120:10: error: assignment to 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
  120 |     list = list->next;
      |          ^
main.c: In function 'double_linked_list_delete_first':
main.c:130:9: warning: comparison of distinct pointer types lacks a cast [-Wcompare-distinct-pointer-types]
  130 |   if (l == l->next) return false;
      |         ^~
main.c:132:32: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
  132 |   double_linked_list_t *head = l->next;
      |                                ^
main.c:133:36: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
  133 |   double_linked_list_t *new_head = head->next;
      |                                    ^~~~
main.c:135:11: error: assignment to 'int *' from incompatible pointer type 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} [-Wincompatible-pointer-types]
  135 |   l->next = new_head;
      |           ^
main.c:136:18: error: assignment to 'int *' from incompatible pointer type 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} [-Wincompatible-pointer-types]
  136 |   new_head->prev = l;
      |                  ^
main.c: In function 'double_linked_list_delete_last':
main.c:147:9: warning: comparison of distinct pointer types lacks a cast [-Wcompare-distinct-pointer-types]
  147 |   if (l == l->prev) return false;
      |         ^~
main.c:149:32: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
  149 |   double_linked_list_t *last = l->prev;
      |                                ^
main.c:150:36: error: initialization of 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
  150 |   double_linked_list_t *new_last = last->prev;
      |                                    ^~~~
main.c:152:18: error: assignment to 'int *' from incompatible pointer type 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} [-Wincompatible-pointer-types]
  152 |   new_last->next = l;
      |                  ^
main.c:153:11: error: assignment to 'int *' from incompatible pointer type 'double_linked_list_t *' {aka 'struct double_linked_list_tag *'} [-Wincompatible-pointer-types]
  153 |   l->prev = new_last;
      |           ^
main.c: At top level:
main.c:162:10: fatal error: util.h: No such file or directory
  162 | #include "util.h"
      |          ^~~~~~~~
compilation terminated.