双向循环链表小改进

//双向循环链表
#include
#include
#include
typedef struct node
{
int data;
struct node *next, *pre;
}link;
//生成该链表
link *creat(link *head,int n)
{
link *p, q;
//初始化
p= head = (link
)malloc(sizeof(link));
head->pre = head;
head->next = head;

while(n--)
{
    q= (link*)malloc(sizeof(link));
    printf("输入一个数据:");
    scanf("%d",&q->data);
    p->next = q;
    q->pre =p;
    q->next = head;
    head->pre = q;
    p =q;
}
return head;

}
void Display(link *head)
{
link *p;
p = head->next;
while(p!=head)
{
printf("%d",p->data);
p= p->next;;
}
printf("\n");
system(“pause”);
}
void main()
{
link *head;
int n;
printf(“有几个数据?”);
scanf("%d",&n);
head = creat(head,n);
Display(head);
}

你可能感兴趣的:(C语言)