当前位置:网站首页>Space shared by two stacks
Space shared by two stacks
2022-07-23 11:59:00 【Look, that's a licking dog】
#include <stdio.h>
#include <malloc.h>
#define MAXSIZE 20
typedef int T;
typedef struct DoubleStack
{
T data[MAXSIZE];
int top1;// head
int top2;// tail
}*dostack;
bool InitStack(dostack s)// initialization
{
if (!s)
return false;
s->top1 = 0;
s->top2 = MAXSIZE - 1;
return true;
}
bool ClearStack(dostack s)// Clear the stack
{
if (!s)
return false;
s->top1 = 0;
s->top2 = MAXSIZE - 1;
return true;
}
bool Is_Empty(dostack s)// Sentenced to empty
{
if (s->top1 == 0 && s->top2 == MAXSIZE - 1)
return true;
else return false;
}
bool Is_Full(dostack s)// Full sentence
{
if (s->top1 + 1 == s->top2)
return true;
else return false;
}
int GetLength(dostack s)// The number of data
{
return s->top1 + MAXSIZE - s->top2;
}
bool Push(dostack s, T val, int num)// Select stack ,1 To the left ,2 For the right
{
if (Is_Full(s))
return false;
if (num == 1)
{
s->data[s->top1++] = val;
}
else if (num == 2)
{
s->data[s->top2--] = val;
}
else false;
return true;
}
T Pop(dostack s,int num)// Select stack ,1 Bit left ,2 For the right
{
if (Is_Empty(s))
return -1;
T tmp;
if (num == 1)
{
if (s->top1 == 0)
return -1;
tmp = s->data[--s->top1];
}
else if (num == 2)
{
if (s->top2 == MAXSIZE - 1)
return -1;
tmp = s->data[++s->top2];
}
else return -1;
return tmp;
}
T GetVal(dostack s, int num)// Get the desired position stack top element
{
if (Is_Empty(s))
return -1;
T tmp;
if (num == 1)
{
if (s->top1 == 0)
return -1;
tmp = s->data[s->top1];
}
else if (num == 2)
{
if (s->top2 == MAXSIZE - 1)
return -1;
tmp = s->data[s->top2];
}
else return -1;
return tmp;
}
void Show(dostack s)// Traverse
{
int i = 0;
while (i < s->top1)
{
printf("%d ", s->data[i++]);
}
printf("\t");
i = s->top2 + 1;
while (i < MAXSIZE)
{
printf("%d ", s->data[i++]);
}
printf("\n");
}
int main()
{
dostack s;
s = (dostack)malloc(sizeof(dostack));
InitStack(s);
for (int i = 1; i <= 5; i++)
{
Push(s, i, 1);
Push(s, i, 2);
}
Show(s);
printf("%d\t", Pop(s, 1));
printf("%d\n", Pop(s, 2));
Show(s);
return 0;
}
边栏推荐
- Service服务
- [untitled]
- Es operation command
- Affichage itératif des fichiers.h5, opérations de données h5py
- Mysqldump batch export MySQL table creation statement
- 规范数据库设计
- ChaosLibrary·UE4开坑笔记
- The user logs in continuously (interruption is allowed) to query SQL
- Project instances used by activiti workflow
- Entrepôt de données 4.0 Notes - acquisition de données commerciales
猜你喜欢

MySQL索引

飞桨高层API实现图像去雨
![[hudi]hudi compilation and simple use of Hudi & spark and Hudi & Flink](/img/6f/e6f5ef79c232d9b27a8334cd8ddaa5.png)
[hudi]hudi compilation and simple use of Hudi & spark and Hudi & Flink

MySQL invalid conn troubleshooting

Data warehouse 4.0 notes - business data collection

Using cluster analysis to build a credit card high-risk customer identification model

数仓4.0笔记——用户行为数据采集四

对.h5文件的迭代显示,h5py数据操作

Affichage itératif des fichiers.h5, opérations de données h5py

3. DQL (data query statement)
随机推荐
方法的定义应用
Data warehouse 4.0 notes - data warehouse environment construction - Yan configuration
Modify the root password of MySQL
数仓4.0笔记——用户行为数据采集四
Entrepôt de données 4.0 Notes - acquisition de données commerciales
The user logs in continuously (interruption is allowed) to query SQL
串
[literature research] search PubMed for papers in journals with specific impact factors
NT68661-屏参升级-RK3128-开机自己升级屏参
Data warehouse 4.0 notes - Data Warehouse Modeling
[doris] configure and basically use the contents system (continue to add content when you have time)
MySQL视图
Mysql database
MySQL transaction rollback mechanism and principle
数仓4.0笔记——业务数据采集——Sqoop
MySQL view
2、MySQL数据管理--DML(添加、修改、删除数据)
MySQL invalid conn troubleshooting
九、实用类
Definition and application of method