当前位置:网站首页>Stack (C language)
Stack (C language)
2022-06-11 23:05:00 【Xiaobai】
typedef int STDataType;
typedef struct Stack
{
STDataType* a;
int top;
int capacity;
}ST;
void StackInit(ST* ps)
{
ps->a = NULL;
ps->top = ps->capacity = 0;
}
void StackDestroy(ST* ps)
{
free(ps->a);
ps->a = NULL;
ps->capacity = ps->top = 0;
}
void StackPush(ST* ps, STDataType x)
{
if (ps->top == ps->capacity)
{
int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;
STDataType* tmp = (STDataType*)realloc(ps->a,sizeof(STDataType) * newcapacity);
ps->capacity = newcapacity;
if (tmp == NULL)
{
exit(-1);
}
ps->a = tmp;
}
ps->a[ps->top++] = x;
}
void StackPop(ST* ps)
{
if (StackEmpty(ps))
return;
ps->top--;
}
STDataType StackTop(ST* ps)
{
return ps->a[ps->top-1];
}
bool StackEmpty(ST* ps)
{
return ps->top == 0;
}
int StackSize(ST* ps)
{
return ps->top;
}
边栏推荐
- What are the pitfalls of redis's current network: using a cache and paying for disk failures?
- [Day8 literature extensive reading] space and time in the child's mind: evidence for a cross dimensional symmetry
- Computer forced shutdown Oracle login failed
- JsonParseException: Unrecognized token ‘username‘: was expecting表单提交登陆数据报错
- Super Codex from the open source world, the authoritative release of China's open source Codex list!
- A method of relay for ultra long distance wireless transmission of low power wireless module
- Google搜索为什么不能无限分页?
- 远程连接redis一会又断开重连
- Processus postgresql10
- IEEE floating point mantissa even round - round to double
猜你喜欢

CVPR 2022 | 元学习在图像回归任务的表现
![[Day8 literature extensive reading] space and time in the child's mind: evidence for a cross dimensional symmetry](/img/c2/e70e7c32c5dc5554dea29cb4627644.png)
[Day8 literature extensive reading] space and time in the child's mind: evidence for a cross dimensional symmetry

0-1 knapsack problem of dynamic programming (detailed explanation + analysis + original code)

Deconstruction of volatile | community essay solicitation

Here we go! Dragon lizard community enters PKU classroom

【Day4 文献精读】Space–time interdependence: Evidence against asymmetric mapping between time and space

【Day10 文献泛读】Temporal Cognition Can Affect Spatial Cognition More Than Vice Versa: The Effect of ...

Cloudcompare source code analysis: read ply file

遇到表格,手动翻页太麻烦?我教你写脚本,一页展示所有数据

The top ten trends of 2022 industrial Internet security was officially released
随机推荐
【Day9 文献泛读】On the (a)symmetry between the perception of time and space in large-scale environments
IEEE-754 floating point converter
Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
SecurityContextHolder.getContext().getAuthentication().getPrincipal()获取到的是username而不是UserDetails
小程序启动性能优化实践
[Day2 intensive literature reading] time in the mind: using space to think about time
2022年安全员-A证考题模拟考试平台操作
Si4432 RF chip scheme typical application of data transmission of wireless communication module of Internet of things
远程连接redis一会又断开重连
One to one correspondence of multiple schematic diagrams and PCB diagrams under Altium designer project
volatile的解构| 社区征文
Google搜索为什么不能无限分页?
Matlab point cloud processing (XXV): point cloud generation DEM (pc2dem)
Application of Lora technology in long distance wireless transmission of water meter reading
【Day13-14 文献精读】Cross-dimensional magnitude interactions arise from memory interference
16 | floating point numbers and fixed-point numbers (Part 2): what is the use of a deep understanding of floating-point numbers?
2022年高处安装、维护、拆除操作证考试题库模拟考试平台操作
产品力进阶新作,全新第三代荣威RX5盲订开启
IEEE floating point mantissa even round - round to double
A method of relay for ultra long distance wireless transmission of low power wireless module