主题:我的链队列为什么结果无限循环
#include<stdio.h>
#include"stdlib.h"
#define FALSE 0
#define TURE 1
typedef struct Node
{
int a;
struct Node *next;
}LinkQueueNode;
typedef struct
{
LinkQueueNode *front;
LinkQueueNode *rear;
}LinkQueue;
int InitQueue(LinkQueue *Q)//*初始化
{
Q->front=(LinkQueueNode *)malloc(sizeof(LinkQueueNode));
if(Q->front!=NULL)
{
Q->rear=Q->front;
Q->front->next=NULL;
return(TURE);
}
else
return(FALSE);
}
int EnterQueue(LinkQueue *Q)//*进栈
{
int c;
LinkQueueNode *NewNode;
NewNode=(LinkQueueNode *)malloc(sizeof(LinkQueueNode));
printf("进队列\n");
printf("进队列的值c");
scanf("%d",&c);
if(NewNode==NULL)
return(FALSE);
while((NewNode!=NULL)&&(c!=0))
{
NewNode->a=c;
NewNode->next=NULL;
Q->rear->next=NewNode;
Q->rear=NewNode;
scanf("%d",&c);
}
return(TURE);
}
int Delete(LinkQueue *Q)//*出栈
{
printf("出队列\n");
LinkQueueNode *p;
while(Q->front!=Q->rear)
{
p=Q->front->next;
Q->front->next=p->next;
printf("%d ",p->a);
}
return(TURE);
}
void main()
{
LinkQueue Q;
InitQueue(&Q);
EnterQueue(&Q);
Delete(&Q);
free(&Q);
}
#include"stdlib.h"
#define FALSE 0
#define TURE 1
typedef struct Node
{
int a;
struct Node *next;
}LinkQueueNode;
typedef struct
{
LinkQueueNode *front;
LinkQueueNode *rear;
}LinkQueue;
int InitQueue(LinkQueue *Q)//*初始化
{
Q->front=(LinkQueueNode *)malloc(sizeof(LinkQueueNode));
if(Q->front!=NULL)
{
Q->rear=Q->front;
Q->front->next=NULL;
return(TURE);
}
else
return(FALSE);
}
int EnterQueue(LinkQueue *Q)//*进栈
{
int c;
LinkQueueNode *NewNode;
NewNode=(LinkQueueNode *)malloc(sizeof(LinkQueueNode));
printf("进队列\n");
printf("进队列的值c");
scanf("%d",&c);
if(NewNode==NULL)
return(FALSE);
while((NewNode!=NULL)&&(c!=0))
{
NewNode->a=c;
NewNode->next=NULL;
Q->rear->next=NewNode;
Q->rear=NewNode;
scanf("%d",&c);
}
return(TURE);
}
int Delete(LinkQueue *Q)//*出栈
{
printf("出队列\n");
LinkQueueNode *p;
while(Q->front!=Q->rear)
{
p=Q->front->next;
Q->front->next=p->next;
printf("%d ",p->a);
}
return(TURE);
}
void main()
{
LinkQueue Q;
InitQueue(&Q);
EnterQueue(&Q);
Delete(&Q);
free(&Q);
}