Problem p02265 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

struct node {
  int key;
  struct node *back, *forward;
};

typedef struct node *NodePointer;

void insert(int);
NodePointer make(int);
NodePointer find(int);
void deleteFirst();
void deleteLast();
void deletel(int);

NodePointer head, tail;

void insert(int num) {
  NodePointer newnode = make(num);
  newnode->back = head;
  newnode->forward = head->forward;
  head->forward->back = newnode;
  head->forward = newnode;
}
NodePointer make(int key) {
  NodePointer newnode = (NodePointer)malloc(sizeof(struct node));
  newnode->key = key;
  return newnode;
}
NodePointer find(int key) {
  for (NodePointer i = head->forward; i != tail; i = i->forward) {
    if (i->key == key)
      return i;
  }
  return NULL;
}
void deleteFirst() {
  NodePointer del = head->forward;
  head->forward = del->forward;
  del->forward->back = head;
  free(del);
}
void deleteLast() {
  NodePointer del = tail->back;
  tail->back = del->back;
  del->back->forward = tail;
  free(del);
}
void deletel(int num) {
  NodePointer del = find(num);
  if (del == NULL)
    return;
  del->forward->back = del->back;
  del->back->forward = del->forward;
  free(del);
}
void showl() {
  for (NodePointer i = head->forward; i != tail->back; i = i->forward) {
    printf("%d ", i->key);
  }
  printf("%d\\n", tail->back->key);
}
int main() {
  head = make(-100);
  tail = make(-100);
  head->forward = tail;
  tail->back = head;

  int n, num;
  string command;
  cin >> n;
  for (int i = 0; i < n; i++) {

    cin >> command;
    if (command[0] == 'd' && command[6] == 'F') {
      deleteFirst();
    } else if (command[0] == 'd' && command[6] == 'L') {
      deleteLast();
    } else if (command[0] == 'i') {
      cin >> num;
      insert(num);
    } else if (command[0] == 'd') {
      cin >> num;
      deletel(num);
    }
  }
  showl();
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

struct node {
  int key;
  struct node *back, *forward;
};

typedef struct node *NodePointer;

void insert(int);
NodePointer make(int);
NodePointer find(int);
void deleteFirst();
void deleteLast();
void deletel(int);

NodePointer head, tail;

void insert(int num) {
  NodePointer newnode = make(num);
  newnode->back = head;
  newnode->forward = head->forward;
  head->forward->back = newnode;
  head->forward = newnode;
}
NodePointer make(int key) {
  NodePointer newnode = (NodePointer)malloc(sizeof(struct node));
  newnode->key = key;
  return newnode;
}
NodePointer find(int key) {
  for (NodePointer i = head->forward; i != tail; i = i->forward) {
    if (i->key == key)
      return i;
  }
  return NULL;
}
void deleteFirst() {
  NodePointer del = head->forward;
  head->forward = del->forward;
  del->forward->back = head;
  free(del);
}
void deleteLast() {
  NodePointer del = tail->back;
  tail->back = del->back;
  del->back->forward = tail;
  free(del);
}
void deletel(int num) {
  NodePointer del = find(num);
  del->forward->back = del->back;
  del->back->forward = del->forward;
  free(del);
}
void showl() {
  for (NodePointer i = head->forward; i != tail->back; i = i->forward) {
    printf("%d ", i->key);
  }
  printf("%d\\n", tail->back->key);
}
int main() {
  head = make(-100);
  tail = make(-100);
  head->forward = tail;
  tail->back = head;

  int n, num;
  string command;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> command;
    if (command[0] == 'd' && command[6] == 'F') {
      deleteFirst();
    } else if (command[0] == 'd' && command[6] == 'L') {
      deleteLast();
    } else if (command[0] == 'i') {
      cin >> num;
      insert(num);
    } else if (command[0] == 'd') {
      cin >> num;
      deletel(num);
    }
  }
  showl();
  return 0;
}