#include<stdio.h>
#include<windows.h>
#include<malloc.h>
{
elemtype data[maxsize];
int front,rear;
{
q=(sqqueue *)malloc(sizeof(sqqueue));
q->front=q->rear=-1;
{
char e;
getchar();
printf("请输入需进队元素:");
scanf("%c",&e);
if(q->rear==maxsize-1)
printf("队满,进队失败!\n");
else
{
q->rear++;
q->data[q->rear]=e;
printf("进队成功\n");
}
{
if(q->rear==q->front)
printf("队列为空!\n");
else
printf("队列不为空!\n");
{
char m;
if(q->rear==q->front)
printf("队空,出队失败!\n");
else
{
q->front++;
m=q->data[q->front];
printf("出队元素为:%c\n",m);
}
{
char m;
getchar();
printf("确定要销毁队列请输入y 否则不销毁!\n");
scanf("%c",&m);
if(m=='y')
{
free(q);
printf("队列已销毁!\n");
exit(0);
}
else
printf("队列未销毁!\n");
{
int n=q->rear-q->front;
return n;
{
sqqueue *q;
int m;
initqueue(q);
while(1)
{
printf("请选择:");
printf("1 进队\n");
printf(" 2 出队\n");
printf(" 3 判断队列是否为空\n");
printf(" 4 销毁队列\n");
printf(" 5 求队列的长度\n");
printf(" 6 退出\n");
scanf("%d",&m);
switch(m)
{
case 1:enqueue(q);break;
case 2:dequeue(q);break;
case 3:queueempty(q);break;
case 4:destroy(q);break;
case 5:printf("队列的长度为:%d\n",length(q));break;
case 6:exit(0);
default:printf("输入错误,请从新输入!\n");
}
}
}
#include<windows.h>
#include<malloc.h>
#define maxsize 100
typedef char elemtype;
{
elemtype data[maxsize];
int front,rear;
}sqqueue;
{
q=(sqqueue *)malloc(sizeof(sqqueue));
q->front=q->rear=-1;
}
{
char e;
getchar();
printf("请输入需进队元素:");
scanf("%c",&e);
if(q->rear==maxsize-1)
printf("队满,进队失败!\n");
else
{
q->rear++;
q->data[q->rear]=e;
printf("进队成功\n");
}
}
{
if(q->rear==q->front)
printf("队列为空!\n");
else
printf("队列不为空!\n");
}
{
char m;
if(q->rear==q->front)
printf("队空,出队失败!\n");
else
{
q->front++;
m=q->data[q->front];
printf("出队元素为:%c\n",m);
}
}
{
char m;
getchar();
printf("确定要销毁队列请输入y 否则不销毁!\n");
scanf("%c",&m);
if(m=='y')
{
free(q);
printf("队列已销毁!\n");
exit(0);
}
else
printf("队列未销毁!\n");
}
{
int n=q->rear-q->front;
return n;
}
{
sqqueue *q;
int m;
initqueue(q);
while(1)
{
printf("请选择:");
printf("1 进队\n");
printf(" 2 出队\n");
printf(" 3 判断队列是否为空\n");
printf(" 4 销毁队列\n");
printf(" 5 求队列的长度\n");
printf(" 6 退出\n");
scanf("%d",&m);
switch(m)
{
case 1:enqueue(q);break;
case 2:dequeue(q);break;
case 3:queueempty(q);break;
case 4:destroy(q);break;
case 5:printf("队列的长度为:%d\n",length(q));break;
case 6:exit(0);
default:printf("输入错误,请从新输入!\n");
}
}
}