当前位置:网站首页>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);
边栏推荐
- 18_Redis_Redis主从复制&&集群搭建
- C# 线程传参
- Learn the method code example of converting timestamp to uppercase date using PHP
- 蜻蜓低代码安全工具平台开发之路
- HUSTPC2022
- SQL 后计算的利器 SPL
- Some Chinese character codes in the user privacy agreement are not standardized, which leads to the display of garbled codes on the web page. It needs to be found and handled uniformly
- 2021-2022學年編譯原理考試重點[華僑大學]
- AtCoder Beginner Contest 254
- 用户隐私协议有些汉字编码不规范导致网页显示乱码,需要统一找出来处理一下
猜你喜欢

vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)

Jenkins Pipeline 应用与实践

Application and practice of Jenkins pipeline

Have you learned the wrong usage of foreach

About text selection in web pages and counting the length of selected text

LeetCode 2310. 个位数字为 K 的整数之和

Introduction to mathjax (web display of mathematical formulas, vector)

20_Redis_哨兵模式

19_Redis_宕机后手动配置主机

LeetCode 209. Minimum length subarray
随机推荐
Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
TiDB 环境与系统配置检查
LeetCode 209. Minimum length subarray
Base64 coding can be understood this way
About text selection in web pages and counting the length of selected text
info [email protected] : The platform “win32“ is incompatible with this module.
Leetcode - Search 2D matrix
原则、语言、编译、解释
GeoServer offline map service construction and layer Publishing
Deploy tidb cluster with tiup
Mfc a dialog calls B dialog function and passes parameters
Jenkins Pipeline 应用与实践
LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
【题解】Educational Codeforces Round 82
Implementation of n queen in C language
CTO如何帮助业务?
03_线性表_链表
Slashgear shares 2021 life changing technology products, which are somewhat unexpected
MFC A对话框调用B对话框函数并传参
kibana 基础操作