第七周项目三 负数把正数赶出队列

来源:互联网 发布:龙歌ol mac版本 编辑:程序博客网 时间:2024/05/21 19:28

问题及代码

main.cpp

/**Copyright(c)2017,烟台大学计算机学院*All right reserved.*文件名:main.cpp sqqueue.h sqqueue.cpp*作者:王万兴*完成日期:2017年10月12日*版本号:v1.0**问题描述:负数把正数赶出队列*输入描述:整数序列*程序输出:见运行结果*/#include <stdio.h>#include <malloc.h>#include "sqqueue.h"int main(){    ElemType a,x;    SqQueue *qu;    //定义队列    InitQueue(qu);  //队列初始化    while (1)    {        printf("输入a值(输入正数进队,负数出队,0结束):");        scanf("%d", &a);        if (a>0)        {            if (!enQueue(qu,a))                printf("  队列满,不能入队\n");                int n=QueueLength(qu);                for (int i=qu->front;i<=qu->front+n-1;i++)                {                    printf("%d ",qu->data[i+1]);                }                printf("\n");//输出队列中的数据        }        else if (a<0)        {            if (!deQueue(qu, x))                printf("  队列空,不能出队\n");                int n=QueueLength(qu);                for (int i=qu->front;i<=qu->front+n-1;i++)                {                    printf("%d ",qu->data[i+1]);                }                printf("\n");//输出队列中的数据        }        else            break;    }    return 0;}
算法库见 

第七周项目二 链队算法库的建立及测试

点击打开链接

运行结果


知识点总结

对链队的入队和出队的运用,可通过for循环将队列数据输出,查看是否正确。



阅读全文
0 0
原创粉丝点击