我正在尝试使用带有头节点的链表实现队列。该程序正在编译,但它给出了运行时错误。你能建议我应该改变什么吗?
显示功能很好。
#include <stdio.h>
#include <stdlib.h>
#define MALLOC(p,n,type) \
p=(type*)malloc(n*sizeof(type)); \
struct node
{
int info;
struct node *link;
};
typedef struct node *NODE;
NODE insert_rear(int item,NODE head)
{
NODE temp;
MALLOC(temp,1,struct node);
temp->info=item;
temp->link=NULL;
if(head==NULL)
{
head->link=temp;
return head;
}
NODE cur;
while(cur->link!=NULL)
{
cur=cur->link;
}
cur->link=temp;
return head;
}
NODE delete_front(NODE head)
{
if(head==NULL)
{
printf("Empty");
return head;
}
NODE temp,first;
first=head->link;
head->link=first->link;
printf("Item deleted is %d",first->info);
free(first);
return head;
}