[求助]SqQueue的作业中malloc不知道错在哪!
如下,谢谢你们了!#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <process.h>
#define MAXQSIZE 100
typedef struct {
int *data;
int len;
int front;
int rear;
}SeqQueue;
int InitQueue (SeqQueue & Q){
Q.data=(Q.data*)malloc (MAXQSIZE*sizeof(Q.data));
if(!Q.data) exit(-1);
Q.front=Q.rear=0;
return 1;
}
int QueueLength(SeqQueue &Q){
return (Q.rear-Q.front+MAXQSIZE)%MAXQSIZE;
}
int EnQueue(SeqQueue & Q,int e){
if((Q.rear+1)%MAXQSIZE==Q.front) return 0;
Q.data[Q.rear]=e;
Q.rear=(Q.rear+1)%MAXQSIZE;
return 1;
}
int DeQueue(SeqQueue&Q,int &e){
if (Q.front==Q.rear)return 0;
e=Q.data[Q.front];
Q.front =(Q.front+1)%MAXQSIZE;
return 1;
}