关于舞伴问题,数据结构高手请进!

来源:百度知道 编辑:UC知道 时间:2024/06/12 04:58:11
.h文件

#define NULL 0

#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef char ElemType;
typedef struct node{
ElemType data;
struct node *next;
}node,*queueptr;
typedef struct{
queueptr front;//队头指针
queueptr rear;//队尾指针
}LinkQueue;
void InitQueue(LinkQueue &Q);
//构造一个空队列
int EnQueue(LinkQueue &Q,ElemType e);
//插入元素e为Q的新的队尾元素
int DeQueue(LinkQueue &Q,ElemType &e);
//若队列不空,则删除Q的队头元素,用e返回其值,并返回OK,否则返回ERROR
int QueueLength(LinkQueue Q);
//返回Q的元素个数,即为队列的长度

.cpp文件

#include<stdio.h>
#include<stdlib.h>
#include"wuban.h"

void InitQueue(LinkQueue &Q){
//构造一个空队列
Q.front=Q.rear=(queueptr)malloc(sizeof(node));
if(!Q.front) exit(OVERFLOW);
Q.front->next=NULL;
}

int EnQueue(LinkQueue &Q,ElemType e){
//插入元素e为Q的新的队尾元素
queueptr

在%c后面加一个\n;
如果还不行的话就在随便定义一个变量加在输入的最后,这个随便取的变量用来存储你最后确定时按得回车键,你用%c不行的原因就是因为最后确认时按得回车也写进去了~