当前位置:网站首页>06_ Stack and queue conversion
06_ Stack and queue conversion
2022-07-02 15:13:00 【Listen to the rain】
Stack and queue conversion
1 Two stacks implement a queue

#include"Stack.h"
typedef int ELEM_TYPE;
// Design the structure we need :two_stack_to_queue
typedef struct TSTQueue
{
Stack s1;// Every time I join the team, I start from the stack s1 Push
Stack s2;// When out of the team , If the stack s2 Not empty , be s2 Out of the stack ,
// Ruozhan s2 It's empty , Then stack s1 The saved data is imported into the stack s2 in , From the stack s2 In the stack
}TSTQueue, * PTSTQueue;
// initialization
void my_Init_Queue(PTSTQueue pq);
// The team push
bool my_Push(PTSTQueue pq, ELEM_TYPE val);
// Out of the team pop You need to delete
bool my_Pop(PTSTQueue pq, ELEM_TYPE* rtval);
//top Gets the value of the queue head element , There is no need to delete
bool my_Top(PTSTQueue pq, ELEM_TYPE* rtval);
// Get the number of effective elements
int my_Get_length(PTSTQueue pq);
// Sentenced to empty
bool my_IsEmpty(PTSTQueue pq);
// Full sentence
bool my_IsFull(PTSTQueue pq);
// Empty
void my_Clear(PTSTQueue pq);
// The destruction
void my_Destroy(PTSTQueue pq);
void my_Show(PTSTQueue pq);
2 Two queues implement a stack

// Design the structure we need :two_queue_to_stack
typedef struct TQTStack
{
Queue q1;// queue 1
Queue q2;// queue 2
}TQTStack, * PTQTStack;
// initialization
void my_Init_stack(PTQTStack ptq);
// Push ( Or pressure stack push)
bool my_Push(PTQTStack ptq, ELEM_TYPE val);
// Out of the stack ( Or bomb stack pop( Get top data , And delete ))//rtval It's an output parameter (C Language speaking )
bool my_Pop(PTQTStack ptq, ELEM_TYPE* rtval);
// Get the top element value top( Get top data )
bool my_Top(PTQTStack ptq, ELEM_TYPE* rtval);
// Get the number of valid data
int my_Get_length(PTQTStack ptq);
// Sentenced to empty
bool my_IsEmpty(PTQTStack ptq);
// Full sentence
bool my_IsFull(PTQTStack ptq);
Capacity expansion
//static void my_Inc(PTQTStack ptq);
// Empty A family lives in one room Emptying is equivalent to driving people out
void my_Clear(PTQTStack ptq);
// The destruction A family lives in one room Destroying is equivalent to driving people out and burning the house
void my_Destroy(PTQTStack ptq);
// Print
void my_Show(PTQTStack ptq);
边栏推荐
- Advanced C language (realize simple address book)
- 记一次报错解决经历依赖重复
- 如何用 Sysbench 测试 TiDB
- CDN 在游戏领域的应用
- 18_Redis_Redis主从复制&&集群搭建
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- 电脑怎么设置扬声器播放麦克风的声音
- Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
- TiDB 软件和硬件环境建议配置
- XML配置文件
猜你喜欢

03_线性表_链表

LeetCode 2310. The number of digits is the sum of integers of K

Dragonfly low code security tool platform development path

Internet Explorer officially retired

Base64 编码原来还可以这么理解

c语言入门--数组

kityformula-editor 配置字号和间距

Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting

LeetCode - 搜索二维矩阵

广州市应急管理局发布7月高温高湿化工安全提醒
随机推荐
Record an interview
C RichTextBox controls the maximum number of lines displayed
About text selection in web pages and counting the length of selected text
HUSTPC2022
AtCoder Beginner Contest 254
How does CTO help the business?
Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
数据分析常见的英文缩写(一)
TiDB 软件和硬件环境建议配置
二叉树的遍历方式主要有:先序遍历、中序遍历、后序遍历、层次遍历。先序、中序、后序其实指的是父节点被访问的次序。若在遍历过程中,父节点先于它的子节点被访问,就是先序遍历;
LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
mathjax 入门(web显示数学公式,矢量的)
LeetCode_字符串_简单_412.Fizz Buzz
TiDB混合部署拓扑
哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
MFC A对话框调用B对话框函数并传参
数据库内容输出有问题怎么解决
Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
数据分析思维分析方法和业务知识——业务指标
N皇后问题的解决