补全下面代码:#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:05 浏览: 78
VS Code C/C++环境配置教程(无法打开源文件“xxxxxx.h” 或者 检测到 #include 错误,请更新includePath) (POSIX API)
```c
#include "stdio.h"
#include "malloc.h"
typedef int datatype;
#define MAXSIZE 50 //队列的最大容量
//定义队列的结构体
typedef struct {
datatype data[MAXSIZE]; //存放队列元素的数组
int front, rear; //队头指针和队尾指针
} c_SeQueue;
typedef struct LNode {
datatype data;
struct LNode *next;
} LNode, *LQueue;
//置空队
c_SeQueue *Init_SeQueue() {
c_SeQueue *sq;
sq = (c_SeQueue*)malloc(sizeof(c_SeQueue));
sq->front = sq->rear = 0;
return sq;
}
LQueue *Init_LQueue() {
LQueue *Lq;
Lq = (LQueue*)malloc(sizeof(LQueue));
Lq->next = NULL;
return Lq;
}
//入队
void Enqueue(c_SeQueue *sq, datatype x) {
if ((sq->rear + 1) % MAXSIZE == sq->front) {
printf("队列已满,无法进队列!\n");
return;
}
sq->data[sq->rear] = x;
sq->rear = (sq->rear + 1) % MAXSIZE;
printf("成功进队列:%d\n", x);
}
void LEnqueue(LQueue *Lq, datatype x) {
LNode *p, *s;
p = Lq;
while (p->next != NULL) {
p = p->next;
}
s = (LNode*)malloc(sizeof(LNode));
s->data = x;
s->next = NULL;
p->next = s;
printf("成功进队列:%d\n", x);
}
//出队
void Dequeue(c_SeQueue *sq) {
if (sq->front == sq->rear) {
printf("队列已空,无法出队列!\n");
return;
}
printf("成功出队列:%d\n", sq->data[sq->front]);
sq->front = (sq->front + 1) % MAXSIZE;
}
void LDequeue(LQueue *Lq) {
LNode *p;
if (Lq->next == NULL) {
printf("队列已空,无法出队列!\n");
return;
}
p = Lq->next;
Lq->next = p->next;
printf("成功出队列:%d\n", p->data);
free(p);
}
//判队空
int IsEmpty(c_SeQueue *sq) {
if (sq->front == sq->rear) {
return 1;
}
return 0;
}
int LIsEmpty(LQueue *Lq) {
if (Lq->next == NULL) {
return 1;
}
return 0;
}
//显示队列
void ShowQueue(c_SeQueue *sq) {
int i = sq->front;
printf("\n队列元素为:");
while (i != sq->rear) {
printf("%d ", sq->data[i]);
i = (i + 1) % MAXSIZE;
}
printf("\n");
}
void LShowQueue(LQueue *Lq) {
LNode *p;
p = Lq->next;
printf("\n队列元素为:");
while (p != NULL) {
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
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);
LEnqueue(Lq, x);
break;
case 2: //出队列
Dequeue(sq);
LDequeue(Lq);
break;
case 3: //判断队列空否
j = IsEmpty(sq);
if (j == 1) printf("此队列为空!!!\n");
else printf("此队列不空。\n");
j = LIsEmpty(Lq);
if (j == 1) printf("此队列为空!!!\n");
else printf("此队列不空。\n");
break;
case 4: //显示队列
ShowQueue(sq);
LShowQueue(Lq);
break;
}
} while (k != 0);
}
```
阅读全文