【c语言】两个栈实现一个队列

这篇博客详细介绍了如何利用两个栈的结构来实现一个队列的功能,包括声明相关文件、编写函数实现以及提供测试用例,展示了C语言在数据结构设计上的应用。
摘要由CSDN通过智能技术生成

声明文件

#ifndef __QUEUE_H
#define __QUEUE_H

#include <stdio.h>
#include <assert.h>
#include <malloc.h>

#define ElemType int
#define SIZE 10
#define TRUE 1
#define FALSE 0

//定义栈
typedef struct stack
{
	ElemType *data;
	int size;
	int top;
}Stack, *Pstack;

//定义队列
typedef struct Queue
{
	Stack sta;
	Stack stb;
}Queue,*Pqueue;

//初始化栈
void InitStack(Pstack stack);

//将val插入栈内
int PushStack(Pstack stack, ElemType val);

//将栈顶的数值用res带出来后删掉
int PopStack(Pstack stack, ElemType *res );

//销毁栈
void DestroyStack(Pstack stack);

//初始化队列
void InitQueue(Pqueue queue);

//入队
int PushQueue(Pqueue queue, ElemType val);

//出队
int PopQueue(Pqueue queue, ElemType *res);

//销毁队
void DestroyQueue(Pqueue queue);

#endif

函数实现文件

#include "Queue.h"

//初始化栈
void InitStack(Pstack stack)
{
	assert(sta
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值