环形队列的问题,不知道哪里出问题了

//环形队列
// 不知道 哪里不对 了
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define max 10
typedef struct Queue {
	int current;
	int store[max];
	int* begin, * end;
}queue;
queue init(void);//初始化
void push(queue*);//入队列
void pop(queue*);//出队列
void show(queue);//遍历队列元素
int main(void) {
	queue army = init();//初始化一个链表
	push(&army);//此后几行是调试 ,结构发现错误了
	push(&army);
	push(&army);
	pop(&army);
	show(army);

	return 0;
}
queue init(void) {
	queue temp;
	temp.current = 0;//现在的元素个数是0
	temp.begin = temp.store;//两个指针都指向 数组
	temp.end = temp.store;

	return temp;
}
void push(queue* temp) {
	if (temp->current == max) {//数据存放满
		puts("队列已满,无法入队列");
		exit(-1);
	}
	puts("请输入要入队列的数据");
	int income;
	scanf_s("%d", &income);
	*(temp->end)++ = income;// 在 end 位置写入 数据,然后end指针后移一位 
	printf("%d已入队列\n", *(temp->end - 1));
	temp->current++; //队列数据 +1
	if (temp->end == &(temp->store[max])) {//如果越界
		temp->end = &(temp->store[0]);//指向开头位置
	}
}
void pop(queue* temp) {
	if (temp->current == 0) {
		puts("队列为空,无法出队列");
		exit(-1);
	}
	printf("%d已出队列", *(temp->begin)++);//begin指针读取数字, 然后 后移一位 
	temp->current--;
	if (temp->begin == &(temp->store[max])) {//如果越界
		temp->begin = &(temp->store[0]);//指向开头位置
	}
}
void show(queue temp) {
	printf("temp.current is %d\n", temp.current);
	while(temp.current != 0) {
		if (temp.begin != temp.store) {
			printf("--%d--", *(temp.begin));
			temp.begin++;
		}
		temp.current--;
	}
}

大家帮忙看一下吧,太难了我

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值