队列的c语言实现求助
求求大佬帮我看看错在哪里{:5_92:}#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TRUE1
#define OVERFLOW -2
#define FALSE 0
#define MAXSIZE 10
typedef struct Queue{
int *base; // 队列首地址
int front;
int rear;
}Queue,*LQueue;//这是我定义的队列结构体
typedef struct Node
{
int data;
struct Node* next;
}Node,*LNode;//节点的结构体
int InitQueue(LQueue Q){
Q->base=(int*)malloc(sizeof(int)*MAXSIZE);
Q->front = Q->rear = NULL;
return TRUE;
}
int Fullor(LQueue Q)
{
Q->front =Q->rear +1;
return(FALSE);
}
int InQueue(LQueue &Q,int &elem)
{
if ((Q->rear + 1) % MAXSIZE == (Q->front))
return FALSE;
Q->base = elem;
Q->rear = (Q->rear + 1) % MAXSIZE;
return TRUE;
}
int OutQueue(LQueue &Q,int &elem)
{
if (Q->front == Q->rear)
return FALSE;
elem= Q->base;
Q->front = (Q->front + 1) % MAXSIZE;
return TRUE;
}
int printQueue(LQueue Q)
{
printf("the queue is:\n");
for(int i =Q->front;i<=Q->rear;++i)
{
printf("%d",Q->base);
}
return TRUE;
}
int main(void)
{
LQueue L;
InitQueue(L);
int i;
int elem;
int h;
printf("input is~:");
for(i=0;i<10;i++)
{
elem=i+25;
InQueue(L,elem);
return TRUE;
}
printQueue(L);
printf("请问你要舍弃多少个数字\n");
scanf("%d", &h);
while (h != 0)
{
OutQueue(L, elem);
h--;
}
printQueue(L);
return TRUE;
}
本帖最后由 1055741510 于 2021-4-20 01:02 编辑
队列初始化 Q->front 和 Q->rear 不能设置为NULL吧 又不是指针 1055741510 发表于 2021-4-20 00:58
队列初始化 Q->front 和 Q->rear 不能设置为NULL吧 又不是指针
我不知道欸,但是也没有报错 YinLee 发表于 2021-4-28 20:14
我不知道欸,但是也没有报错
NULL代表的是数字0,字符串(null),字符null,布尔假,所以编译器没有报错
页:
[1]