当前位置:网站首页>06_栈和队列转换
06_栈和队列转换
2022-07-02 12:00:00 【听*雨声】
栈和队列转换
1 两个栈实现一个队列
#include"Stack.h"
typedef int ELEM_TYPE;
//设计我们需要的那个结构体:two_stack_to_queue
typedef struct TSTQueue
{
Stack s1;//每次入队的时候从给栈s1入栈
Stack s2;//出队的时候,如果栈s2不空,则s2出栈,
//若栈s2为空,则将栈s1保存的数据导入到栈s2中,再从栈s2中出栈
}TSTQueue, * PTSTQueue;
//初始化
void my_Init_Queue(PTSTQueue pq);
//入队 push
bool my_Push(PTSTQueue pq, ELEM_TYPE val);
//出队 pop 需要删除操作
bool my_Pop(PTSTQueue pq, ELEM_TYPE* rtval);
//top 获取队头元素值, 不需要删除操作
bool my_Top(PTSTQueue pq, ELEM_TYPE* rtval);
//获取其有效元素个数
int my_Get_length(PTSTQueue pq);
//判空
bool my_IsEmpty(PTSTQueue pq);
//判满
bool my_IsFull(PTSTQueue pq);
//清空
void my_Clear(PTSTQueue pq);
//销毁
void my_Destroy(PTSTQueue pq);
void my_Show(PTSTQueue pq);
2 两个队列实现一个栈
//设计我们需要的那个结构体:two_queue_to_stack
typedef struct TQTStack
{
Queue q1;//队列1
Queue q2;//队列2
}TQTStack, * PTQTStack;
//初始化
void my_Init_stack(PTQTStack ptq);
//入栈(或者叫压栈 push)
bool my_Push(PTQTStack ptq, ELEM_TYPE val);
//出栈(或者叫弹栈 pop(获取顶部数据,并且删除))//rtval是一个输出参数(C语言讲到)
bool my_Pop(PTQTStack ptq, ELEM_TYPE* rtval);
//获取顶部元素值 top(获取顶部数据)
bool my_Top(PTQTStack ptq, ELEM_TYPE* rtval);
//获取其有效数据个数
int my_Get_length(PTQTStack ptq);
//判空
bool my_IsEmpty(PTQTStack ptq);
//判满
bool my_IsFull(PTQTStack ptq);
扩容
//static void my_Inc(PTQTStack ptq);
//清空 一间房住了一户人 清空相当于把人赶出去
void my_Clear(PTQTStack ptq);
//销毁 一间房住了一户人 销毁相当于把人赶出去还把房烧了
void my_Destroy(PTQTStack ptq);
//打印
void my_Show(PTQTStack ptq);
边栏推荐
- Points clés de l'examen de principe de compilation pour l'année scolaire 2021 - 2022 [Université chinoise d'outre - mer]
- fatal: unsafe repository is owned by someone else 的解决方法
- qml 弹窗框架,可定制
- Actual combat sharing of shutter screen acquisition
- 学习使用php实现公历农历转换的方法代码
- Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
- Jenkins Pipeline 应用与实践
- Fatal: unsafe repository is owned by someone else
- LeetCode_字符串_简单_412.Fizz Buzz
- Ad20 cannot select the solution of component packaging in PCB editor
猜你喜欢
Actual combat sharing of shutter screen acquisition
Simple verification code generator for 51 single chip microcomputer experiment
Advanced C language (realize simple address book)
c语言入门--数组
LeetCode 2320. Count the number of ways to place the house
CTO如何帮助业务?
LeetCode 2310. 个位数字为 K 的整数之和
. Net core logging system
Ad20 cannot select the solution of component packaging in PCB editor
Base64 coding can be understood this way
随机推荐
Btrace- (bytecode) dynamic tracking tool
使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式
List集合&UML图
kibana 基础操作
2021-2022學年編譯原理考試重點[華僑大學]
buuctf-pwn write-ups (7)
TiDB跨数据中心部署拓扑
GeoServer offline map service construction and layer Publishing
[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)
Li Chuang EDA learning notes 15: draw border or import border (DXF file)
TiDB混合部署拓扑
Onnx+tensorrt: write preprocessing operations to onnx and complete TRT deployment
Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
871. Minimum refueling times: simple priority queue (heap) greedy question
C语言实现N皇后问题
871. 最低加油次数 : 简单优先队列(堆)贪心题
Why can't browsers read JSX?
Actual combat sharing of shutter screen acquisition
MFC CString to char*
. Net core logging system