#include<stdio.h> #include<stdlib.h>
typedef struct DoubleLink{ struct DoubleLink * front; struct DoubleLink * next; int element; }List;
List *head; List *end;
void InitList() { head=(List*)malloc(sizeof(List)); end=(List*)malloc(sizeof(List)); head->next=end; end->front=head; head->front=NULL; end->next=NULL; }
void head_insert(int key) { List* temp=(List*)malloc(sizeof(List)); temp->element=key; temp->next=head->next; temp->front=head; head->next=temp; temp->next->front=temp; }
void end_insert(int key) { List* temp=(List*)malloc(sizeof(List)); temp->element=key; temp->next=end; temp->front=end->front; end->front=temp; temp->front->next=temp; }
void index_insert(int date,int key) { int index=find(data); List* temp=head; if(index==-1) { head_insert(key); return; } for(int i=0;i<index;i++) { temp=temp->next; } List* new=(List*)malloc(sizeof(List)); new->element=key; new->next=temp->next; new->front=temp; temp->next=new; new->next->front=new; }
void delete(int key) { int index=find(key); if(index==-1) { return; } List* temp=head; for(int i=0;i<index;i++) { temp=temp->next; } temp->front->next=temp->next; temp->next->front=temp->front; free(temp); }
int find(int data) { List*temp=head; int i=-1; while(temp!=end) { if(temp->element==data) break; temp=temp->next; i++; } return i; }
|