当前位置:网站首页>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);
边栏推荐
- 传感器数据怎么写入电脑数据库
- LeetCode 2320. 统计放置房子的方式数
- TiDB 环境与系统配置检查
- Internet Explorer officially retired
- CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
- Advanced C language (realize simple address book)
- List集合&UML图
- C code audit practice + pre knowledge
- Kityformula editor configure font size and spacing
- 可视化搭建页面工具的前世今生
猜你喜欢
随机推荐
你不知道的Set集合
C language exercises - (array)
为什么只会编程的程序员无法成为优秀的开发者?
2021-2022學年編譯原理考試重點[華僑大學]
二叉树的遍历方式主要有:先序遍历、中序遍历、后序遍历、层次遍历。先序、中序、后序其实指的是父节点被访问的次序。若在遍历过程中,父节点先于它的子节点被访问,就是先序遍历;
【NOI模拟赛】伊莉斯elis(贪心,模拟)
【C语言】详解指针的初阶和进阶以及注意点(1)
871. 最低加油次数 : 简单优先队列(堆)贪心题
Wechat applet uses towxml to display formula
MFC timer usage
Implementation of n queen in C language
使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式
Application of CDN in game field
Huawei interview question: no palindrome string
. Net core logging system
[c voice] explain the advanced pointer and points for attention (2)
C # delay, start the timer in the thread, and obtain the system time
19_Redis_宕机后手动配置主机
btrace-(字节码)动态跟踪工具
表格响应式布局小技巧