当前位置:网站首页>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;
}
边栏推荐
- 基于模板配置的数据可视化平台
- JsonParseException: Unrecognized token ‘username‘: was expecting表单提交登陆数据报错
- The second bullet of in-depth dialogue with the container service ack distribution: how to build a hybrid cloud unified network plane with the help of hybridnet
- Mobile terminal - picture timeline of swipe effect
- The remote connection to redis is disconnected and reconnected after a while
- 2022年高处安装、维护、拆除操作证考试题库模拟考试平台操作
- 2022年安全员-A证考题模拟考试平台操作
- Super Codex from the open source world, the authoritative release of China's open source Codex list!
- Common problems of Converged Communication published in February | Yunxin small class
- [day11-12 intensive literature reading] on languages in memory: an internal clock account of space-time interaction
猜你喜欢

唤醒手腕 - 神经网络与深度学习(Tensorflow应用)更新中

Application of Lora wireless communication module Lora technology in smart home light control

One to one correspondence of multiple schematic diagrams and PCB diagrams under Altium designer project

【Day9 文献泛读】On the (a)symmetry between the perception of time and space in large-scale environments

How to make scripts executable anywhere

16 | 浮点数和定点数(下):深入理解浮点数到底有什么用?

产品力进阶新作,全新第三代荣威RX5盲订开启

Library management system

Google搜索為什麼不能無限分頁?

Cloudcompare source code analysis: read ply file
随机推荐
postgresql10 进程
Jsonparseexception: unrecognized token 'username': was expecting error when submitting login data
Want to be iron man? It is said that many big men use it to get started
SDNU_ ACM_ ICPC_ 2022_ Weekly_ Practice_ 1st (supplementary question)
Here we go! Dragon lizard community enters PKU classroom
Postgresql10 process
Analysis on the market prospect of smart home based on ZigBee protocol wireless module
Exercise 8-8 moving letters (10 points)
【Day8 文献泛读】Space and Time in the Child‘s Mind: Evidence for a Cross-Dimensional Asymmetry
GMN of AI medicine article interpretation
Solution to page locking caused by xshell accidentally pressing ctrl+s
[Day10 literature extensive reading] temporary cognition can affect spatial cognition more than vice versa: the effect of
Review C language I
[day4 literature intensive reading] space – time interdependence: evidence against Asymmetric mapping between time and space
mysql——find_in_set用法
Application of Lora wireless communication module Lora technology in smart home light control
栈(C语言)
小程序启动性能优化实践
PHP+MYSQL图书管理系统(课设)
Research Report on development trend and competitive strategy of global customized power supply industry