jay1.c
来自「有关数据结构的一些例子。用C语言编写的。非常有价值的程序。对初学者有指导借鉴意义」· C语言 代码 · 共 66 行
C
66 行
#define NULL 0
#include "stdio.h"
#include "malloc.h"
typedef int datatype;
typedef struct dnode
{ datatype data;
struct dnode *prior,*next;
} dlinklist;
dlinklist *head,*l;
dlinklist *CREAT()
{ int ch;
dlinklist *h,*s,*r;
h=(struct dnode *)malloc(sizeof(dlinklist));
r=h;
printf("\ndlinklist:\n");
scanf("%d",&ch);
while(ch!=0)
{ s=(struct dnode *)malloc(sizeof(dlinklist));
s->data=ch;
r->next=s;
r=s;
printf("%d\t",s->data);
scanf("%d",&ch);
}
r->next=NULL;
return(h);
}
INSERT(x)
datatype x;
{ dlinklist *s;
s=(struct dnode *)malloc(sizeof(dlinklist));
s->data=x;
s->prior=head->prior;
s->next=head;
head->prior->next=s;
head->prior=s;
}
DELETE(p)
dlinklist *p;
{
p->prior->next=p->next;
p->next->prior=p->prior;
free(p);
}
main()
{ int m;
head=CREAT();
printf("\nINSERT:\n");
scanf("%d",&m);
INSERT(head,m);
while(head!=NULL)
{ printf("%d\t",head->next->data);
head=head->next;
}
printf("\nDELETE:\n");
scanf("%d",l->data);
DELETE(l);
while(head!=NULL)
{ printf("%d\t",head->next->data);
head=head->next;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?