下面是源代码:
#include<stdio.h>
#include<stdlib.h>
typedef int ElemType;
struct QNode
{
ElemType data;
QNode* next;
};
struct Queue
{
QNode* rear;
QNode* front;
};
Queue* create()
{
QNode* q;
Queue* Q;
q=new QNode;
q->next=NULL;
Q->front=Q->rear=q;
return Q;
}
void EnQueue(Queue* Q,ElemType e)
{
QNode* N;
N=new QNode;
N->next=NULL;
N->data=e;
Q->rear->next=N;
Q->rear=N;
}
void DelQueue(Queue* Q)
{
QNode* N;
N=Q->front->next;
Q->front->next=N->next;
free(N);
}
void TraveQueue(Queue* Q)
{
while(Q->front->next!=NULL){
printf("%d",Q->front->next->data);
Q->front->next=Q->front->next->next;
}
}
int main()
{
Queue* Q;
Q=create();
EnQueue(Q,5);
EnQueue(Q,7);
EnQueue(Q,9);
TraveQueue(Q);
DelQueue(Q);
TraveQueue(Q);
}
单步调试的时候,无法删除元素,问题出在DelQueue函数里面,也就是Q->front->next=N->next求大神给予指导;