一大堆错误,帮我改改
带头结点的循环链表表示队列 只设一个队尾指针,写置空,判队空,入队,出队,初始化队#include <stdio.h>
#include<stdio.h>
#include<malloc.h>
typedef struct node{
int data;
struct node *next;
}Linklist;
typedef struct{
Linklist *rear;
}LinkQ;
LinkQ *SetQueue(){
LinkQ *Q;
Q=(LinkQ *)malloc(sizeof(LinkQ));
Q->rear->next=Q->rear;
return Q;
}
int EmptyQueue(LinkQ *Q){
if(!Q->rear)
return 1;
else
return 0;
}
LinkQ *Add(LinkQ *Q,int x){
LinkQ *p;
p=(LinkQ *)malloc(sizeof(LinkQ));
p->rear->data=x;
p->next=Q->rear->next;
Q->rear->next=p;
Q->rear=p;
return Q;
}
LinkQ *Delete(LinkQ *Q){
LinkQ *p;
if(!EmptyQueue){
p=Q->rear->next;
Q->rear->next=p->next;
free(p);
}
return Q;
}
LinkQ InitQueue(LinkQ *Q){
Q->rear=Q->rear->next;
return Q;
}
void main(){
int n,choice;
LinkQ *S;
do{
printf("1.建空队\n");
printf("2.判空队\n");
printf("3.入队\n");
printf("4.出队\n");
printf("5.置空队\n");
printf("6.退出\n");
printf("请选择:");
scanf("%d",&choice);
switch(choice){
case 1:SetQueue(); break;
case 2:EmptyQueue(S);break;
case 3:printf("输入元素,以-1结束:");
scanf("%d",&n);
while(n!=-1){
Add(S,n);
scanf("%d",&n);
};break;
case 4:Delete(S);break;
case 5:InitQueue(S);break;
}
}while(choice!=6);
}