hsb11223344
hsb11223344
2017-09-27 13:36

队列报数问题 为什么不能输出啊

  • 数据结构队列的应用

#include
#include
#define N 8
typedef struct
{
int data[N];
int front, rear;
}SqQueue;
bool deQueue(SqQueue*p, int e)
{
if (p->front == p->rear)
return false;
p->front = (p->front + 1) % N;
e = p->data[p->front];
return true;
}
bool QueueEmpty(SqQueue*p)
{
return(p->rear == NULL);
}
bool enQueue(SqQueue*p, int e)
{
if ((p->rear + 1) % N == p->front)
return false;
p->rear = (p->rear + 1) % N;
p->data[p->rear] = e;

}
void InitQueue(SqQueue*p)
{
p = (SqQueue*)malloc(sizeof(SqQueue));
p->front = p->rear = 0;
}
void DestroyQueue(SqQueue*p)
{
free(p);
}
void number(int n)
{
int i, e;
SqQueue *p;
InitQueue(p);
for (i = 1; i <= N; i++)
{
enQueue(p, i);
}
printf("报数出列顺序:");
while (!QueueEmpty(p))
{
deQueue(p, e);
printf("%d", e);
if (!QueueEmpty(p))
{
deQueue(p, e);
enQueue(p, e);
}

}
DestroyQueue(p);

}

int main()
{
int i;
printf("初始序列:");
for ( i = 1; i <=N; i++)
{
printf("%d", i);
}
printf("\n");
number(N);
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答