C语言 顺序队列的插入

来源:百度知道 编辑:UC知道 时间:2024/05/15 14:58:52
本人C语言菜鸟。麻烦帮忙改改程序。
#include <stdio.h>
#include <stdlib.h>

#define MAXSIZE 100

typedef struct _Queue
{
int front;
int rear;
int data[MAXSIZE];
}Queue;

void addqueue(Queue *v)
{
int x;
if(v->front==(v->rear+1)% MAXSIZE)
{
printf("The Queue is full!\n");
exit(1);
}
else
{
v->rear=(v->rear+1)% MAXSIZE;
v->data[v->rear]=x;
}
}

creat(Queue * v,int x)
{
if(((v->rear)+1)%MAXSIZE==v->front)
{
printf("The Queue is full!\n");
return 0;
}
else
{
v->data[v->rear]=x;
v->rear=((v->rear)+1)%MAXSIZE;
return 1;
}
}

void PrintEle(Queue *v)
{
int i=v->front;
while(i%MAXSIZE!=v->rear)
{
printf(

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

#define MAXSIZE 100

typedef struct _Queue
{
int front;
int rear;
int data[MAXSIZE];
}Queue;

void addqueue(Queue *v,int num)
{

if(v->front==(v->rear+1)% MAXSIZE)
{
printf("The Queue is full!\n");
exit(1);
}
else
{
v->data[v->rear]=num; /*就是你所写的那两句,稍作修改,再 交换位置即可*/
v->rear=(v->rear+1)% MAXSIZE;
}
}

creat(Queue * v,int x)
{
if(((v->rear)+1)%MAXSIZE==v->front)
{
printf("The Queue is full!\n");
return 0;
}
else
{
v->data[v->rear]=x;
v->rear=((v->rear)+1)%MAXSIZE;
return 1;
}
}

void PrintEle(Queue *v)
{
int i=v->front;
while(i%MAXSIZE!=v->re