当前位置:网站首页>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);
边栏推荐
- 06_栈和队列转换
- [untitled] leetcode 2321 Maximum score of concatenated array
- Learn the method code example of converting timestamp to uppercase date using PHP
- AtCoder Beginner Contest 254
- [QNX hypervisor 2.2 user manual]6.3 communication between guest and external
- LeetCode 209. 长度最小的子数组
- Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
- TiDB 软件和硬件环境建议配置
- Li Chuang EDA learning notes 15: draw border or import border (DXF file)
- PHP method to get the index value of the array item with the largest key value in the array
猜你喜欢

Error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.

蜻蜓低代码安全工具平台开发之路

JMeter script parameterization
![[noi simulation] Elis (greedy, simulation)](/img/a2/f8c8ab3bc8dd779327be3f76990976.png)
[noi simulation] Elis (greedy, simulation)

21_Redis_浅析Redis缓存穿透和雪崩

MFC 定时器使用

Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)

17_Redis_Redis发布订阅

【C语言】详解指针的初阶和进阶以及注意点(1)

Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
随机推荐
Internet Explorer officially retired
[untitled] leetcode 2321 Maximum score of concatenated array
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
HUSTPC2022
蜻蜓低代码安全工具平台开发之路
IE 浏览器正式退休
qml 弹窗框架,可定制
MFC console printing, pop-up dialog box
【NOI模拟赛】伊莉斯elis(贪心,模拟)
06_栈和队列转换
Application and practice of Jenkins pipeline
Implementation of n queen in C language
info [email protected] : The platform “win32“ is incompatible with this module.
Why can't programmers who can only program become excellent developers?
Mfc a dialog calls B dialog function and passes parameters
17_Redis_Redis发布订阅
Recommended configuration of tidb software and hardware environment
2021-2022學年編譯原理考試重點[華僑大學]
Map介绍
mathjax 入门(web显示数学公式,矢量的)