Insert the bidirectional loop linked list, delete the operation as shown in figure:
#include <stdio.h> #include <stdlib.h> #include <malloc.h> typedef struct lnode{int data;
struct Lnode *next;
struct Lnode *prior;
}node,*linklist;
int createlinklist (linklist &l,int length) {linklist head,temp,hmove;
L = (linklist) malloc (sizeof (Node)); if (!
L) {printf ("malloc action error");
return 0;
} l->next = L;
L->prior = L;
Hmove = head = L;
int j=0;
for (; j<length;j++) {temp = (linklist) malloc (sizeof (Node));
if (!temp) {printf ("malloc action error");
return 0;
} scanf ("%d", &temp->data);
Temp->next = head;
Head->prior = temp;
Temp->prior = Hmove;
Hmove->next = temp;
Hmove = temp;
} return 1;
} int printlinklist (linklist L) {linklist head;
head = L;
Head = head->next;
while (head!=l) {printf ("%d", head->data);
Head = head->next; } return 1;
} int insertlinklist (linklist l,int i,int Element) {linklist head,temp;
head = L;
Head = head->next;
int j = 0;
while (j<i-1) {++j;
Head = head->next;
if (head = = L) {break;
}} if (j<i-1) {printf ("Insert ERROR");
return 0;
temp = (linklist) malloc (sizeof (Node));
if (!temp) {printf ("malloc action error");
return 0;
} Temp->data = element;
Temp->next = head->next;
Temp->prior =head;
Head->next = temp;
Temp->next->prior = temp;
return 1;
} int deletelinklist (linklist l,int i) {linklist head;
int j = 0;
head = L;
Head = head->next;
while (j<i-1) {++j;
Head = head->next;
if (head==l) {break;
}} if (j<i-1) {printf ("Insert ERROR");
return 0;
} printf ("%d\n", head->data); Head->prior->next = head->next;
Head->next->prior = head->prior;
Free (head);
return 1;
} int main () {linklist L;
int length;
printf ("Create linklist\n");
scanf ("%d", &length);
Createlinklist (l,length);
Printlinklist (L);
printf ("\ninsert linklist\n");
int index,element;
scanf ("%d%d", &index,&element);
Insertlinklist (l,index,element);
Printlinklist (L);
printf ("\ndelete linklist\n");
scanf ("%d", &index);
Deletelinklist (L,index);
Printlinklist (L);
}