《数据结构》实验报告
实验序号 5 实验项目名称 队列的操作
附源程序清单
1
#inc lude<stdlib.h>
#inc lude<stdio.h>
#define ERROR 1
#define OK 0
#define OVERFLOW 1typedef int QElemType;typedef int Status;
#define MAXQSIZE 100 //最大队列长度typedef s truc t {
QElemType*bas e; //动态分配存储空间int front; //头指针若队列不空指向队列头元素int rear; //尾指针若队列不空 //指向队列尾元素的下一个位置
}SqQueue;
//构造一个空队列Q
Status InitQueue(SqQueue&Q)
{
Q.bas e=(QElemType*)malloc (MAXQSIZE*sizeof(QElemType));if (!Q.base) exit (OVERFLOW);//存储分配失败
Q.front=Q.rear=0;return OK;
}
//插入元素e为Q的新的队尾元素
Status EnQueue(SqQueue&Q,QElemType e)
{if((Q.rear+1)%MAXQ SIZE==Q.front)return ERROR; //队列满
Q.base[Q.rear]=e;
Q.rear=(Q.rear+1)%MAXQSIZE;return OK;
}
//若队列不空则删除Q的队头元素用e返回其值并返回OK; 否则返回ERRORStatus DeQueue(SqQueue&Q,QElemType&e)
{if(Q.front==Q.rear) return ERROR;e=Q.base[Q.front];
Q.front=(Q.front+1)%MAXQ SIZE;return OK;
}void main()
{char i;int n=0;
QElemType j=0;
SqQueue S;
InitQueue(S); //初始化队列printf("元素入队列,回车结束\n");while((i=getchar())!='\n')
{
EnQueue(S,i); //元素入队列n++;
}printf("元素出队列\n");for(i=0; i<n; i++)
{
DeQueue(S,j); //元素出队列printf("%c",j);
}printf("\n");
}
2
#inc lude<stdlib.h>
#inc lude<stdio.h>
#define ERROR 1
#define OK 0
#define OVERFLOW 1typedef int QElemType;typedef int Status;int tag 1=0;int tag2=1;
#define MAXQSIZE 5 //最大队列长度typedef s truc t {
QElemType*bas e; //动态分配存储空间int front; //头指针若队列不空指向队列头元素int rear; //尾指针若队列不空 //指向队列尾元素的下一个位置
}SqQueue;
//构造一个空队列Q
Status InitQueue(SqQueue&Q)
{
Q.base=(QElemType*)malloc (MAXQSIZE*sizeof(QElemType));if (!Q.base) exit (OVERFLOW);//存储分配失败
Q.front=Q.rear=0;return OK;
}
//插入元素e为Q的新的队尾元素
Status EnQueue(SqQueue&Q,QElemType e)
{if((Q.rear+1)%MAXQ SIZE==Q.front)
{if((((Q.rear+1) /MAXQSIZE))==tag 1)
{printf("队列为空\n");
}if((((Q.rear+1) /MAXQ S IZE))==tag2)
{printf("队列为满\n");
}
}//return ERROR; //队列满
Q.base[Q.rear]=e;
Q.rear=(Q.rear+1)%MAXQSIZE;return OK;
}
//若队列不空则删除Q的队头元素用e返回其值并返回OK; 否则返回ERRORStatus DeQueue(SqQueue&Q,QElemType&e)
{if(Q.front==Q.rear) r eturn ERROR;e=Q.base[Q.front];
Q.front=(Q.front+1)%MAXQ SIZE;return OK;
}void main()
{char i;int n=0;
QElemType j=0;
SqQueue S;
InitQueue(S); //初始化队列printf("元素入队列,回车结束\n");while((i=getchar())!='\n')
{
EnQueue(S,i); //元素入队列n++;
}printf("元素出队列\n");for(i=0;i<n;i++)
{
DeQueue(S,j); //元素出队列printf("%c",j);
}printf("\n");
}
2
#inc lude<stdlib.h>
#inc lude<stdio.h>
#define ERROR 1
#define OK 0
#define OVERFLOW 1typedef int QElemType;typedef int Status;
#define MAXQSIZE 5//最大队列长度static int tag=1;static int k=0;typedef s truc t
{
QElemType*bas e; //动态分配存储空间int front; //头指针若队列不空指向队列头元素int rear; //尾指针若队列不空 //指向队列尾元素的下一个位置
}SqQueue;
//构造一个空队列Q
Status InitQueue(SqQueue&Q)
{
Q.base=(QElemType*)malloc (MAXQSIZE*sizeof(QElemType));if (!Q.base) exit (OVERFLOW);//存储分配失败
Q.front=Q.rear=0;return OK;
}
//插入元素e为Q的新的队尾元素
Status EnQueue(SqQueue&Q,QElemType e)
{
Q.base[Q.rear]=e;
Q.rear=(Q.rear+1)%MAXQSIZE;return OK;
}
//若队列不空则删除Q的队头元素用e返回其值并返回OK; 否则返回ERRORStatus DeQueue(SqQueue&Q,QElemType&e)
{e=Q.bas e[Q.front];
Q.front=(Q.front+1)%MAXQ SIZE;
//if((((Q.front)%MAXQSIZE))==Q.front)
{tag=2;
}k++;return OK;
}void main()
{char i;int n=0;
QElemType j=0;
SqQueue S;
InitQueue(S); //初始化队列printf("元素入队列,回车结束\n");while((i=getchar())!='\n')
{
EnQueue(S,i); //元素入队列n++;//4
}printf("元素出队列\n");for(i=0; i<n; i++)
{
DeQueue(S,j); //元素出队列printf("%c",j);
}
// printf("%d",k);if((k/MAXQSIZE)==1)
{
printf("\n头尾相连 队列为满");}if(tag==1)
{printf("\n头尾相连 队列为空");}printf("\n");
RAKsmart商家一直以来在独立服务器、站群服务器和G口和10G口大端口流量服务器上下功夫比较大,但是在VPS主机业务上仅仅是顺带,尤其是我们看到大部分主流商家都做云服务器,而RAKsmart商家终于开始做云服务器,这次试探性的新增美国硅谷机房一个方案。月付7.59美元起,支持自定义配置,KVM虚拟化,美国硅谷机房,VPC网络/经典网络,大陆优化/精品网线路,支持Linux或者Windows操作...
可以看到这次国庆萤光云搞了一个不错的折扣,香港CN2产品6.5折促销,还送50的国庆红包。萤光云是2002年创立的商家,本次国庆活动主推的是香港CN2优化的机器,其另外还有国内BGP和高防服务器。本次活动力度较大,CN2优化套餐低至20/月(需买三个月,用上折扣+代金券组合),有需求的可以看看。官方网站:https://www.lightnode.cn/地区CPU内存SSDIP带宽/流量价格备注购...
提速啦的来历提速啦是 网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑 由赣州王成璟网络科技有限公司旗下赣州提速啦网络科技有限公司运营 投资1000万人民币 在美国Cera 香港CTG 香港Cera 国内 杭州 宿迁 浙江 赣州 南昌 大连 辽宁 扬州 等地区建立数据中心 正规持有IDC ISP CDN 云牌照 公司。公司购买产品支持3天内退款 超过3天步退款政策。提速啦的市场定位提速啦主...