#include<stdio.h>
#include<string.h>
#include<stdlib.h>
??
#define N 2000000
??
struct node {
????????int key;
????????struct node *next;
????????struct node *prev;
};
typedef struct node *NodePointer;
??
typedef struct{
????????char ask[20];
????????int key2;
}Roll;
??
NodePointer insert(int);
NodePointer finditem(int);
NodePointer delete(int);
void deleteFirst(void);
void deleteLast(void);
void list(void);
??
NodePointer head;
Roll Ask[N];
??
int main() {
??
????????int n;
????????int i;
??
??
????????scanf("%d", &n);
????????head = (NodePointer)malloc(sizeof(struct node));
????????head->next = NULL;
????????head->key = 0;
??
??
????????for (i = 0; i < n; i++) {
????????????????scanf("%s", Ask[i].ask);
??
????????????????if(strcmp(Ask[i].ask, "deleteFirst") == 0) {
????????????????????????deleteFirst();
????????????????}
????????????????else if (strcmp(Ask[i].ask, "deleteLast") == 0) {
????????????????????????????????deleteLast();
????????}
????????else {
????????????????scanf("%d", &Ask[i].key2);
????????????????if (strcmp(Ask[i].ask, "insert") == 0)
????????????????????????insert(Ask[i].key2);
????????????????else if (strcmp(Ask[i].ask, "delete") == 0)
????????????????????????delete(Ask[i].key2);
????????}
??????????????????
}
??
????????list();
??
????????return 0;
}
NodePointer insert(int keydata) {
????????NodePointer newnode,n;
????????newnode = (NodePointer)malloc(sizeof(struct node));
????????????????newnode->next = head->next;
????????????????newnode->key = keydata;
????????????????if (head->next != NULL)
????????????????newnode->next->prev = newnode;
????????????????head->next = newnode;
????????????????newnode->prev = head;
????????????????return newnode;
??
}
NodePointer finditem(int value) {
????????NodePointer n;
????????for (n = head; n -> next != NULL; n = n->next) {
????????????????if (n->next->key == value) return n;
????????}
????????return NULL;
}
??
void list(void) {
????????NodePointer n;
for (n = head->next; n->next != NULL; n = n->next) {
????????printf("%d ", n->key);???? 
??
}
????????printf("%d", n->key);
????????printf("\n");
}
NodePointer delete(int keydata) {
????????NodePointer n, delnode;
????????if ((n = finditem(keydata)) != NULL) {
????????????????delnode = n->next;
????????????????n->next = delnode->next;
????????????????if(n->next!=NULL)
????????????????n->next->prev = n;
????????????????free(delnode);
????????????????return n;
????????}
????????else return NULL;
}
void deleteFirst(void) {
????????NodePointer delnode;
????????delnode = head->next;
????????head->next = delnode->next;
????????head->next->prev = head;
????????free(delnode);
??
}
void deleteLast(void){
????????NodePointer n,delnode;
????????for (n = head; n->next!= NULL; n = n->next) {
????????};
????????delnode = n;
????????n->prev->next = NULL;
??
????????free(delnode);
??
}