用C语言编个可用队列,从队列尾部推入数据,从队列首部提取数据

来源:百度知道 编辑:UC知道 时间:2024/09/22 18:23:10
用C语言编个可用队列,从队列尾部推入数据,从队列首部提取数据

速度!急求!

struct Node
{
int num;
struct Node *prev;
struct Node *next;
};
struct Node *head;

int delque()
{
int temp;
struct Node *p=head;
if(head->next==head)
{
temp=head->num;
free(head);
head=NULL;
return temp;

}
temp=head->num;
head->prev->next=head->next;
head->next->prev=head->prev;
head=head->next;
free(p);
return temp;
}
void insque(int x)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
if(!temp)
{
perror("memory is full!");
exit(-1);
}
temp->num=x;
if(head==NULL)
{
head=temp;
head->next=head;
head->prev=head;
return;
}
temp->prev=head->prev;
temp->next=head;
head->prev->next=temp;
head->prev=temp;
}