当前位置:网站首页>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);
边栏推荐
- Bit by bit of OpenCV calling USB camera
- 数据库内容输出有问题怎么解决
- About text selection in web pages and counting the length of selected text
- C code audit practice + pre knowledge
- MFC CString 转 char*
- 学习使用php实现公历农历转换的方法代码
- Tmall product details interface (APP, H5 end)
- AtCoder Beginner Contest 254
- LeetCode 2320. Count the number of ways to place the house
- Sharp tool SPL for post SQL calculation
猜你喜欢

Makefile separates file names and suffixes

Obsidian installs third-party plug-ins - unable to load plug-ins

CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E

.NET Core 日志系统

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

Leetcode - Search 2D matrix

Solve the problem that El radio group cannot be edited after echo

MathML to latex

LeetCode 2320. 统计放置房子的方式数

MFC 定时器使用
随机推荐
[noi simulation] Elis (greedy, simulation)
taobao. logistics. dummy. Send (no logistics delivery processing) interface, Taobao store delivery API interface, Taobao order delivery interface, Taobao R2 interface, Taobao oau2.0 interface
解决el-radio-group 回显后不能编辑问题
Factal: Unsafe repository is owned by someone else Solution
牛客练习赛101
Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
[QNX Hypervisor 2.2用户手册]6.3 Guest与外部之间通信
Arithmetic operations and related exercises in C language
Leetcode - Search 2D matrix
C# 线程传参
Internet Explorer officially retired
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
MFC CString 转 char*
Sharp tool SPL for post SQL calculation
Xilinx Vivado set *.svh as SystemVerilog Header
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
LeetCode - 搜索二维矩阵
Onnx+tensorrt: write preprocessing operations to onnx and complete TRT deployment
List集合&UML图
C#延时、在线程中开启定时器、获取系统时间