#include<stdio.h> #include<stdlib.h> #define ok 1 #define error 0 typedef int Status; typedef char ElemType; typedef struct node{ int data; struct node *prior; struct node *next; }Node; Node * create(Node *L,int i){ int n; int j=0; Node *q=L;//保存头结点 while(j<i){ Node *p; p=(Node *)malloc(sizeof(Node)); printf("请输入结点%d的data: ",j); scanf("%d ",&n); p->data=n; p->prior=q; p->next=NULL; q->next=p; q=p; j++; } return L; } Status Insert(Node *L,int i,int m){ int j=0; Node *p=NULL; while(j<i){ L=L->next; j++; } p=(Node *)malloc(sizeof(Node)); p->data=m; p->prior=L; p->next=L->next; L->next->prior=p; L->next=p; return ok; } void Traverse(Node *L){ L=L->next; while(L){ printf("%d ",L->data); L=L->next; } } void main(){ int m=5; Node *p=NULL; Node *L; L=(Node *)malloc(sizeof(Node)); L->next=NULL; L->prior=NULL; p=create(L,m); Traverse(L); Insert(L,2,6); Traverse(L); }