当前位置:网站首页>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;
}
边栏推荐
- [day15 literature extensive reading] numerical magnetic effects temporary memories but not time encoding
- Research Report on development trend and competitive strategy of global seabed leakage detection system industry
- The top ten trends of 2022 industrial Internet security was officially released
- [day11-12 intensive literature reading] on languages in memory: an internal clock account of space-time interaction
- 926. flip string to monotonic increment
- Is it too troublesome to turn pages manually when you encounter a form? I'll teach you to write a script that shows all the data on one page
- C language simple exercise No.17, about the combination of for and while loops
- C# List. Can foreach temporarily / at any time terminate a loop?
- Unity3d C#开发微信小游戏音频/音效播放问题解决过程分享
- H. 265 introduction to coding principles
猜你喜欢

Fonctionnement de la plate - forme d'examen de simulation pour les agents de sécurité - Questions d'examen de certificat a en 2022

2022 online summit of emerging market brands going to sea will be held soon advance AI CEO Shou Dong will be invited to attend

Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data

CVPR 2022 | 元学习在图像回归任务的表现

【Day15 文献泛读】Numerical magnitude affects temporal memories but not time encoding
![[day6-7 intensive literature reading] a unifying Bayesian framework accounting for spatiotemporal interactions with a](/img/a9/c0f3a6b76d789d47172727d353d9be.png)
[day6-7 intensive literature reading] a unifying Bayesian framework accounting for spatiotemporal interactions with a

Library management system

想做钢铁侠?听说很多大佬都是用它入门的

2022年安全员-B证理论题库及模拟考试

Want to be iron man? It is said that many big men use it to get started
随机推荐
What are the pitfalls of redis's current network: using a cache and paying for disk failures?
[day13-14 intensive literature reading] cross dimensional magnetic interactions arise from memory interference
Exercise 11-2 find week (15 points)
Alibaba cloud server MySQL remote connection has been disconnected
Exercise 8-8 judging palindrome string (20 points)
Message queue MySQL table that stores message data
【Day11-12 文献精读】On magnitudes in memory: An internal clock account of space-time interaction
Four rounding modes in IEEE754 standard
Leetcode must review 20 lintcode (5466421166978227)
Research Report on development trend and competitive strategy of global reverse osmosis membrane cleaning agent industry
postgresql10 进程
C language simple exercise No.17, about the combination of for and while loops
2022安全员-C证判断题模拟考试平台操作
volatile的解构| 社区征文
Application of Lora technology in long distance wireless transmission of water meter reading
【delphi】判断文件的编码方式(ANSI、Unicode、UTF8、UnicodeBIG)
Php+mysql library management system (course design)
【Day3 文献精读】Asymmetrical time and space interference in Tau and Kappa effects
Why can't Google search page infinite?
Exercise 8-8 moving letters (10 points)