一个很奇怪的队列问题,不知道什么这个队列老在死循环打印
#include <stdio.h>
#include <stdlib.h>
#define MaxSize 10
struct queue_node
{
int data;
struct queue_node *next;
};
typedef struct queue_node queue_list;
typedef queue_list *link;
link front = NULL;
link rear = NULL;
link addqueue(int value)
{
link new ;
new = (link)malloc(sizeof(queue_list));
new->data = value;
new->next = NULL;
if(rear == NULL)
front = new;
else
rear->next = new;
rear = new;
return rear;
}
int delqueue()
{
int temp;
link top ;
top = (link)malloc(sizeof(queue_list));
if(!top)
{
fprintf(stderr,"Malloc top is failed \n");
return -1;
}
if(front != NULL)
{
top = front;
front = front->next;
temp = top->data;
free(top);
return temp;
}
else
return -1;
}
int main()
{
int select ;
int i,temp,temp2 = 0;
link point = NULL;
printf("[1] Input a data \n");
printf("[2] Output a data \n");
printf("[3] Exit \n");
printf("Please select :\n");
if( ( temp = scanf("%d",&select)) != 1)
{
printf("\n Entry error exit now \n");
return -1;
}
if(select != 3){
do
{
switch(select)
{
case 1: printf("Please input the input vale ==>");
scanf("%d",&temp);
point = addqueue(temp);
printf("The content of queue:");
point = front;
while(point)
{
printf("[%d]",point->data);
point->next;
}
break;
case 2: if((temp = delqueue()) == -1 )
printf("The queue is empty!!!\n ");
else{
printf("The output value is [%d] \n",temp);
printf("The content of queue:");
while(point != NULL)
{
printf("[%d]",point->data);
point->next;
}
}
break;
}
printf(" \n[1] Input a data \n");
printf("[2] Output a data \n");
printf("[3] Exit \n");
printf("Please select :\n");
if( ( temp = scanf("%d",&select)) != 1)
{
printf("\n Entry error exit now \n");
return -1;
}
printf("\n");
}while(select != 3);
}
return 0;
}