Language: C++

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

#define INSERT '0'
#define MOVE '1'
#define ERASE '2'
#define END 1000000001

typedef struct Cell {
	int data;
	struct Cell* prev;
	struct Cell* next;
} Cell;

Cell* newCell(int data) {
    Cell* cell = malloc(sizeof(Cell));
    cell->data = data;
    cell->prev = NULL;
    cell->next = NULL;
    return cell;
}

void print(Cell *cell) {
    // 先頭まで移動する
	while (cell->prev != NULL) {
		cell = cell->prev;
	}

	do {
	    if (cell->data != END) {
			printf("%d\n", cell->data);
			cell = cell->next;
		}
	} while (cell->next != NULL);
}

int isEnd(Cell *cursor) {
	return (cursor != NULL && cursor->data == END);
}

int isFront(Cell *cursor) {
	return (cursor != NULL && cursor->prev == NULL);
}

Cell* insert(Cell *cursor, int data) {
	if (isFront(cursor)) {
		Cell *new = newCell(data);
		new->next = cursor;
		cursor->prev = new;
		return new;
	}

	Cell *new = newCell(data);
	Cell *prev = cursor->prev;
	new->prev = prev;
	new->next = cursor;
	prev->next = new;
	cursor->prev = new;
	return new;
}

Cell* move(Cell *cursor, int d) {
	if (d == 0) {
		return cursor;
	}

	if (d < 0) {
		while (d++) {
			if (isFront(cursor)) {
				printf("Cursor is already front.\n");
				exit(1);
			}

			cursor = cursor->prev;
		}
		return cursor;
	}

	while (d--) {
		if (cursor->next == NULL) {
			printf("Cursor has no next.\n");
			exit(2);
		}

		cursor = cursor->next;
	}
	
	return cursor;
}

Cell* erase(Cell *cursor) {
	if (isEnd(cursor)) {
		return cursor;
	}

	Cell *prev = cursor->prev;
	Cell *next = cursor->next;
	prev->next = next;
	next->prev = prev;
	free(cursor);
	return prev;
}


void answer() {
	Cell *cursor;
	int q = 0;
	int d = 0;
	char a[15];

	fgets(a, 15, stdin);
	q = atoi(a);
	cursor = newCell(END);

	while (q--) {
	    fgets(a, 15, stdin);
		if (a[0] == INSERT) {
            cursor = insert(cursor, atoi(a+2));
		} else if (a[0] == MOVE) {
		    cursor = move(cursor, atoi(a+2));
		} else if (a[0] == ERASE) {
		    cursor = erase(cursor);
		}

	}

	print(cursor);
}

int test() {
	Cell *cur = newCell(END);
	cur = insert(cur, 1);
	cur = insert(cur, 2);
	cur = insert(cur, 3);
	cur = move(cur, 1);
	cur = erase(cur);
	print(cur);
	return 0;
}

int main(void){
	answer();
}




Compiler output:
a.cc: In function 'Cell* newCell(int)':
a.cc:17:24: error: invalid conversion from 'void*' to 'Cell*' [-fpermissive]
   17 |     Cell* cell = malloc(sizeof(Cell));
      |                  ~~~~~~^~~~~~~~~~~~~~
      |                        |
      |                        void*
a.cc: In function 'Cell* insert(Cell*, int)':
a.cc:48:23: error: expected unqualified-id before 'new'
   48 |                 Cell *new = newCell(data);
      |                       ^~~
a.cc:49:20: error: expected type-specifier before '->' token
   49 |                 new->next = cursor;
      |                    ^~
a.cc:50:35: error: expected type-specifier before ';' token
   50 |                 cursor->prev = new;
      |                                   ^
a.cc:51:27: error: expected type-specifier before ';' token
   51 |                 return new;
      |                           ^
a.cc:54:15: error: expected unqualified-id before 'new'
   54 |         Cell *new = newCell(data);
      |               ^~~
a.cc:56:12: error: expected type-specifier before '->' token
   56 |         new->prev = prev;
      |            ^~
a.cc:57:12: error: expected type-specifier before '->' token
   57 |         new->next = cursor;
      |            ^~
a.cc:58:25: error: expected type-specifier before ';' token
   58 |         prev->next = new;
      |                         ^
a.cc:59:27: error: expected type-specifier before ';' token
   59 |         cursor->prev = new;
      |                           ^
a.cc:60:19: error: expected type-specifier before ';' token
   60 |         return new;
      |                   ^