用C语言编写一算法将一链队列的元素依次取出,并打印这些元素值

关于数据结构的。。
2024-12-26 07:46:47
推荐回答(1个)
回答1:

#define NULL 0
#include
typedef struct point
{
int c;
struct point *next;
struct point *prior;
}node;
node * creat(node *head,int n)
{
node *p,*pt;
int i;
//p=(node *)malloc(sizeof(node));
//scanf("%d",&p->c);
scanf("%d",&head->c);
p=head;
pt=p;
i=1;
while(i{
p=(node *)malloc(sizeof(node));
scanf("%d",&p->c);
p->prior=pt;
pt->next=p;
pt=p;
i++;
}
p->next=NULL;
return head;
}
void bianli(node *head)
{
node *p;
p=head;
printf("\n");
while(p!=NULL)
{
printf("%d ",p->c);
p=p->next;
}
}
int main()
{
node *head;
int n;
head=(node *)malloc(sizeof(node));
printf("input the size of linklist:");
scanf("%d",&n);
head=creat(head,n);
bianli(head);
getch();
}