- struct dnode
- {
- int data;
- struct dnode *prv;
- struct dnode *next;
- };
- struct dnode *creatlist(int a)//建立双向链
- {
- struct dnode *head=NULL,*p=NULL;
- head=(struct dnode *)malloc(sizeof(struct dnode));
- if(!head)
- {
- perror("head malloc");
- }
- head->prv=head->next=NULL;
- while(a)
- {
- p=(struct dnode *)malloc(sizeof(struct dnode));
- if(!p)
- {
- perror("p malloc");
- }
- p->data=a--;
- p->next=head->next;
- head->next=p;
- p->prv=head;
- if(p->next!=NULL)
- p->next->prv=p;
- p=NULL;
- }
- return head;
- }
复制代码
我自己写的双向链表 帮看下写的对嘛? |