补全代码:#include "stdio.h" #include "malloc.h" typedef int datatype; #define MAXSIZE 50 //队列的最大容量 //定义队列的结构体 typedef struct { }; //置空队 //入队 //出队 //判队空 //显示队列 void main() { c_SeQueue *sq; LQueue *Lq; int j,k; datatype x; sq=Init_SeQueue(); Lq=Init_LQueue(); do { printf("\n\n\n\n"); printf("\t\t\t 队列子系统\n"); printf("\t\t*******************************\n"); printf("\t\t* 1----进 队 列 *\n"); printf("\t\t* 2----出 队 列 *\n"); printf("\t\t* 3----队列空否 *\n"); printf("\t\t* 4----显示队列 *\n"); printf("\t\t* 0----返 回 *\n"); printf("\t\t*******************************\n"); printf("\t\t 请选择菜单项(0-4):"); scanf("%d",&k);getchar(); switch(k) { case 1: //进队列 printf("\n 请输入要进队列的数据:"); ; ; break; case 2: //出队列 ; break; case 3: //判断队列空否 ; if (j==1) printf("此队列为空!!!"); else printf("此队列不空。"); break; case 4: //显示队列 printf("\n 此队列有数据:"); ; } }while(k!=0); }
时间: 2023-08-10 13:07:07 浏览: 161
补全代码:
```c
#include "stdio.h"
#include "malloc.h"
typedef int datatype;
#define MAXSIZE 50 //队列的最大容量
//定义循环队列的结构体
typedef struct
{
datatype data[MAXSIZE]; //存储队列元素的数组
int front; //队头指针
int rear; //队尾指针
} c_SeQueue;
//定义链式队列的结构体
typedef struct node
{
datatype data; //存储队列元素的数据域
struct node *next; //指向下一个节点的指针
} LNode, *LQueue;
//置空队
c_SeQueue *Init_SeQueue()
{
c_SeQueue *sq;
sq = (c_SeQueue *)malloc(sizeof(c_SeQueue));
sq->front = 0;
sq->rear = 0;
return sq;
}
//入队
void EnQueue(c_SeQueue *sq, datatype x)
{
if ((sq->rear + 1) % MAXSIZE == sq->front)
{
printf("队列已满,无法入队!");
return;
}
sq->data[sq->rear] = x;
sq->rear = (sq->rear + 1) % MAXSIZE;
}
//出队
datatype DeQueue(c_SeQueue *sq)
{
if (sq->front == sq->rear)
{
printf("队列为空,无法出队!");
return -1;
}
datatype x = sq->data[sq->front];
sq->front = (sq->front + 1) % MAXSIZE;
return x;
}
//判队空
int IsEmpty(c_SeQueue *sq)
{
return sq->front == sq->rear ? 1 : 0;
}
//显示队列
void Display(c_SeQueue *sq)
{
int i = sq->front;
printf("\n");
while (i != sq->rear)
{
printf("%d ", sq->data[i]);
i = (i + 1) % MAXSIZE;
}
}
void main()
{
c_SeQueue *sq;
LQueue *Lq;
int j, k;
datatype x;
sq = Init_SeQueue();
Lq = Init_LQueue();
do
{
printf("\n\n\n\n");
printf("\t\t\t 队列子系统\n");
printf("\t\t*******************************\n");
printf("\t\t* 1----进 队 列 *\n");
printf("\t\t* 2----出 队 列 *\n");
printf("\t\t* 3----队列空否 *\n");
printf("\t\t* 4----显示队列 *\n");
printf("\t\t* 0----返 回 *\n");
printf("\t\t*******************************\n");
printf("\t\t 请选择菜单项(0-4):");
scanf("%d", &k);
getchar();
switch (k)
{
case 1: //进队列
printf("\n 请输入要进队列的数据:");
scanf("%d", &x);
EnQueue(sq, x);
break;
case 2: //出队列
x = DeQueue(sq);
printf("\n 出队列的数据是:%d", x);
break;
case 3: //判断队列空否
j = IsEmpty(sq);
if (j == 1)
printf("此队列为空!!!");
else
printf("此队列不空。");
break;
case 4: //显示队列
printf("\n 此队列有数据:");
Display(sq);
}
} while (k != 0);
}
```
阅读全文