Language: C


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
  int key;
  Node *next,*prev;
};

Node *nil;

Node* listsearch(int key){
  Node *cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(void){
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  Node *cur = nil->next;
  int isf = 0;
  while(1){
    if(cur == nil) break;
    if(isf++ > 0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key,n,i;
  int size=0;
  int np=0,nd=0;
  char com[20];

  scanf("%d",&n);
  init();
  for(i=0 ; i<n ; i++){
    scanf("%s%d",com,&key);
    if(com[0] == 'i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0] == 'd'){
      if(strlen(com) > 6){
        if(com[6] == 'F') deleteFirst();
        else if(com[6] == 'L') deleteLast();
      }
      else{
         deleteKey(Key);
         nd++;
      }
      size--;
    }
  }
  printList();

  return 0;
}

Compiler output:
main.c:8:3: error: unknown type name 'Node'
    8 |   Node *next,*prev;
      |   ^~~~
main.c:11:1: error: unknown type name 'Node'; use 'struct' keyword to refer to the type
   11 | Node *nil;
      | ^~~~
      | struct 
main.c:13:1: error: unknown type name 'Node'; use 'struct' keyword to refer to the type
   13 | Node* listsearch(int key){
      | ^~~~
      | struct 
main.c: In function 'listsearch':
main.c:14:3: error: unknown type name 'Node'; use 'struct' keyword to refer to the type
   14 |   Node *cur = nil->next;
      |   ^~~~
      |   struct 
main.c:14:18: error: request for member 'next' in something not a structure or union
   14 |   Node *cur = nil->next;
      |                  ^~
main.c:15:26: error: request for member 'key' in something not a structure or union
   15 |   while(cur != nil && cur->key != key){
      |                          ^~
main.c:16:14: error: request for member 'next' in something not a structure or union
   16 |     cur = cur->next;
      |              ^~
main.c: In function 'init':
main.c:22:10: error: 'Node' undeclared (first use in this function)
   22 |   nil = (Node *)malloc(sizeof(Node));
      |          ^~~~
main.c:22:10: note: each undeclared identifier is reported only once for each function it appears in
main.c:22:16: error: expected expression before ')' token
   22 |   nil = (Node *)malloc(sizeof(Node));
      |                ^
main.c:23:6: error: request for member 'next' in something not a structure or union
   23 |   nil->next = nil;
      |      ^~
main.c:24:6: error: request for member 'prev' in something not a structure or union
   24 |   nil->prev = nil;
      |      ^~
main.c: In function 'printList':
main.c:28:3: error: unknown type name 'Node'; use 'struct' keyword to refer to the type
   28 |   Node *cur = nil->next;
      |   ^~~~
      |   struct 
main.c:28:18: error: request for member 'next' in something not a structure or union
   28 |   Node *cur = nil->next;
      |                  ^~
main.c:33:20: error: request for member 'key' in something not a structure or union
   33 |     printf("%d",cur->key);
      |                    ^~
main.c:34:14: error: request for member 'next' in something not a structure or union
   34 |     cur = cur->next;
      |              ^~
main.c: At top level:
main.c:39:17: error: unknown type name 'Node'
   39 | void deleteNode(Node *t){
      |                 ^~~~
main.c: In function 'deleteFirst':
main.c:47:3: error: implicit declaration of function 'deleteNode' [-Wimplicit-function-declaration]
   47 |   deleteNode(nil->next);
      |   ^~~~~~~~~~
main.c:47:17: error: request for member 'next' in something not a structure or union
   47 |   deleteNode(nil->next);
      |                 ^~
main.c: In function 'deleteLast':
main.c:51:17: error: request for member 'prev' in something not a structure or union
   51 |   deleteNode(nil->prev);
      |                 ^~
main.c: In function 'deleteKey':
main.c:55:14: error: implicit declaration of function 'listSearch'; did you mean 'listsearch'? [-Wimplicit-function-declaration]
   55 |   deleteNode(listSearch(key));
      |              ^~~~~~~~~~
      |              listsearch
main.c: In function 'insert':
main.c:59:3: error: unknown type name 'Node'; use 'struct' keyword to refer to the type
   59 |   Node *x = (Node *)malloc(sizeof(Node));
      |   ^~~~
      |   struct 
main.c:59:14: error: 'Node' undeclared (first use in this function)
   59 |   Node *x = (Node *)malloc(sizeof(Node));
      |              ^~~~
main.c:59:20: error: expected expression before ')' token
   59 |   Node *x = (Node *)malloc(sizeof(Node));
      |                    ^
main.c:60:4: error: request for member 'key' in something not a structure or union
   60 |   x->key = key;
      |    ^~
main.c:61:4: error: request for member 'next' in something not a structure or union
   61 |   x->next = nil->next;
      |    ^~
main.c:61:16: error: request for member 'next' in something not a structure or union
   61 |   x->next = nil->next;
      |                ^~
main.c:62:6: error: request for member 'next' in something not a structure or union
   62 |   nil->next->prev = x;
      |      ^~
main.c:63:6: error: request for member 'next' in something not a structure or union
   63 |   nil->next = x;
      |      ^~
main.c:64:4: error: request for member 'prev' in something not a structure or union
   64 |   x->prev = nil;
      |    ^~
main.c: In function 'main':
main.c:88:20: error: 'Key' undeclared (first use in this function); did you mean 'key'?
   88 |          deleteKey(Key);
      |                    ^~~
      |                    key