错误太多了,只能简单修改下编译错误
// Q1062027.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define OK 1
#define ERROR 0
int M=0;
int N=0;
typedef int Status;
typedef struct ElemType
{
int level;
char name[20];
char gender;
char ID[20];
}ElemType;
typedef struct Node //结点结构
{
ElemType data;
struct Node *next;
}Node,*QueuePtr;
typedef struct
{
QueuePtr front,rear;
} LinkQueue;
Status InitQueue(LinkQueue **Q) // 队列初始化
{
QueuePtr p;
p=(QueuePtr)malloc(sizeof(QueuePtr));
if(!p)
{
printf("内存分配失败");
return ERROR;
}
*Q=(LinkQueue*)malloc(sizeof(LinkQueue));
if(!(*Q))
{
printf("内存分配失败");
return ERROR;
}
p->next=NULL;
(*Q)->front=p;
(*Q)->front=(*Q)->rear;
return OK;
}
Status EnQueue(LinkQueue *Q, ElemType e) //入队
{
QueuePtr s=(QueuePtr)malloc(sizeof(Node));
if(!s)
{
printf("内存分配失败");
return ERROR;
}
s->data=e;
s->next=NULL;
Q->rear->next=s; //把拥有元素e的新节点s赋值给队尾的后继节点
Q->rear=s; //把当前s设置为队尾节点,rear指向s
return OK;
}
Status DeQueue(LinkQueue *Q,ElemType *e) //出队
{
QueuePtr p;
if(Q->front==Q->rear)
{
printf("队列为空!");
return ERROR;
}
p=Q->front->next; // 将预删除的队头结点暂存给p
*e=p->data; // 将删除的队头结点赋值给e 即出队
Q->front->next=p->next; // 将原队头结点后继p->next 赋值给现投结点后继
if(Q->rear==p)
{
Q->rear=Q->front; //若队头是队尾,则删除后将rear指向头结点
}
free(p);
return OK;
}
Status PriorEnQueue(LinkQueue *Q1,LinkQueue *Q2,ElemType e)
{
if(e.level==3)
{
EnQueue(Q1,e);
}
else
{
EnQueue(Q2,e);
}
return OK;
}
Status PriorDeQueue(LinkQueue*Q1,LinkQueue*Q2)
{
ElemType e;
if(!(Q2->front==Q2->rear))
DeQueue(Q2,&e);
else if(!(Q1->front==Q1->rear))
DeQueue(Q1,&e);
else
{
return ERROR;
}
return OK;
}
Status GetIN(LinkQueue*Q1,LinkQueue*Q2,ElemType*e)
{
int i;
int n;
printf("请输入前来就诊的病人数量:");
scanf("%d",&n);
for(i=M;i<M+n;i++)
{
printf("\n请输入第%d个病人的优先级:",i+1);
scanf("%d",&e[i].level);
printf("\n请输入第%d个病人的姓名:",i+1);
scanf("%s",e[i].name);
printf("\n请输入第%d个病人的性别:",i+1);
scanf("%s",&e[i].gender);
printf("\n请输入第%d个病人的身份证:",i+1);
scanf("%s",e[i].ID);
PriorEnQueue(Q1,Q2,e[i]);
}
M=M+n;
return OK;
}
Status ShowInformation(ElemType *e)
{
int i;
LinkQueue *Q1,*Q2;
InitQueue(&Q1);
InitQueue(&Q2);
PriorDeQueue(Q1,Q2);
printf("优先级----------姓名----------性别----------身份证\n");
for(i=N;i<N;i++)
{
printf("\n");
printf("%5d %5s %5s %10s",e[i].level,e[i].name,&e[i].gender,e[i].ID);
}
return OK;
}
int main()
{
LinkQueue Q1,Q2;
Q1.front=Q1.rear=NULL;
Q2.front=Q2.rear=NULL;
ElemType e;
GetIN(&Q1,&Q2,&e);
ShowInformation(&e);
return 0;
}