hsb11223344 2017-09-27 13:36
浏览 891

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

#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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘