当前位置:网站首页>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);
边栏推荐
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
- Tmall product details interface (APP, H5 end)
- List集合&UML图
- Bit by bit of OpenCV calling USB camera
- 微信小程序使用towxml显示公式
- Wechat applet uses towxml to display formula
- 871. Minimum refueling times: simple priority queue (heap) greedy question
- Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
- C# richTextBox控制显示最大行数
猜你喜欢

MFC timer usage

可视化搭建页面工具的前世今生

Internet Explorer officially retired

Why can't programmers who can only program become excellent developers?

微信小程序使用towxml显示公式

【C语言】详解指针的初阶和进阶以及注意点(1)
[email protected] : The platform “win32“ is incompatible with this module."/>info [email protected] : The platform “win32“ is incompatible with this module.

. Net core logging system

kibana 基础操作

C#代码审计实战+前置知识
随机推荐
Base64 coding can be understood this way
Makefile 分隔文件名与后缀
微信小程序使用towxml显示公式
电脑怎么设置扬声器播放麦克风的声音
[QNX Hypervisor 2.2用户手册]6.3 Guest与外部之间通信
MFC timer usage
C RichTextBox controls the maximum number of lines displayed
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
Why can't browsers read JSX?
taobao. trade. memo. Add (add remarks to a transaction) interface, Taobao store flag insertion interface, Taobao order flag insertion API interface, oauth2.0 interface
Implement a server with multi process concurrency
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
Xilinx Vivado set *. svh as SystemVerilog Header
871. Minimum refueling times: simple priority queue (heap) greedy question
Niuke Practice 101
Ad20 cannot select the solution of component packaging in PCB editor
用户隐私协议有些汉字编码不规范导致网页显示乱码,需要统一找出来处理一下
Internet Explorer officially retired
HUSTPC2022
Fatal: unsafe repository is owned by someone else