当前位置:网站首页>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);
边栏推荐
- 【NOI模拟赛】伊莉斯elis(贪心,模拟)
- 数据库内容输出有问题怎么解决
- [untitled] leetcode 2321 Maximum score of concatenated array
- 哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
- 微信小程序使用towxml显示公式
- 牛客练习赛101
- CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
- forEach的错误用法,你都学废了吗
- Factal: Unsafe repository is owned by someone else Solution
- taobao. trade. memo. Add (add remarks to a transaction) interface, Taobao store flag insertion interface, Taobao order flag insertion API interface, oauth2.0 interface
猜你喜欢
随机推荐
Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly
JMeter script parameterization
TiDB 软件和硬件环境建议配置
报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
Leetcode - Search 2D matrix
LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
[Space & single cellomics] phase 1: single cell binding space transcriptome research PDAC tumor microenvironment
taobao. trades. sold. Get query the transaction data that the seller has sold (according to the creation time), Taobao store sales order query API interface, Taobao R2 interface, Taobao oauth2.0 trans
C# 线程传参
GeoServer offline map service construction and layer Publishing
kityformula-editor 配置字号和间距
Fatal: unsafe repository is owned by someone else
MFC timer usage
TiDB 环境与系统配置检查
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
mathjax 入门(web显示数学公式,矢量的)
Introduction to C language -- array
Mfc a dialog calls B dialog function and passes parameters
蜻蜓低代码安全工具平台开发之路