当前位置:网站首页>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);
边栏推荐
- Mfc a dialog calls B dialog function and passes parameters
- Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
- TiDB跨数据中心部署拓扑
- Tidb cross data center deployment topology
- . Net core logging system
- 871. 最低加油次数 : 简单优先队列(堆)贪心题
- 牛客练习赛101
- 06_栈和队列转换
- 学习使用php实现公历农历转换的方法代码
- C # delay, start the timer in the thread, and obtain the system time
猜你喜欢

Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly

C语言习题---(数组)
![[noi simulation] Elis (greedy, simulation)](/img/a2/f8c8ab3bc8dd779327be3f76990976.png)
[noi simulation] Elis (greedy, simulation)

Application and practice of Jenkins pipeline

表格响应式布局小技巧

LeetCode 209. 长度最小的子数组

CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
[email protected] : The platform “win32“ is incompatible with this module."/>info [email protected] : The platform “win32“ is incompatible with this module.

Table responsive layout tips

Have you learned the wrong usage of foreach
随机推荐
Dragonfly low code security tool platform development path
C code audit practice + pre knowledge
kibana 基础操作
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
[c voice] explain the advanced pointer and points for attention (2)
Niuke Practice 101
Topology architecture of the minimum deployment of tidb cluster
Add vector formula in rich text editor (MathType for TinyMCE, visual addition)
php获取数组中键值最大数组项的索引值的方法
[noi Simulation Competition] scraping (dynamic planning)
btrace-(字节码)动态跟踪工具
Application of CDN in game field
Implementation of n queen in C language
Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
How to conduct TPC-C test on tidb
AtCoder Beginner Contest 254
LeetCode 2310. The number of digits is the sum of integers of K
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
學習使用php實現公曆農曆轉換的方法代碼