十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
#include
#include
#include
#include
typedef struct Stack
{
int *a;
int top;
int capacity;
}ST;
void StackInit(ST* arr)
{
assert(arr);
arr->a = NULL;
arr->top = arr->capacity = 0;
}
void StackDestory(ST* arr)
{
assert(arr);
free(arr->a);
arr->capacity = arr->top = 0;
}
void StackPush(ST* arr, int x)
{
assert(arr);
if (arr->top == arr->capacity)
{
int newcapacity = arr->capacity == 0 ? 4 : arr->capacity * 2;
ST* new = realloc(arr->a,sizeof(int) * newcapacity);
if (new == NULL)
{
exit(-1);
}
arr->a = new;
arr->capacity = newcapacity;
}
arr->a[arr->top] = x;
arr->top++;
arr->capacity++;
}
void StackPop(ST* arr)
{
assert(arr);
assert(arr->top >0);
arr->top--;
}
int StackTop(ST* arr)
{
return arr->a[arr->top - 1];
}
int StackSize(ST* arr)
{
return arr->top;
}
bool StackEmpty(ST* arr)
{
return arr->a[arr->top] == 0;
}
int main()
{
ST ps;
StackInit(&ps);
StackPush(&ps, 1);
StackPush(&ps, 1);
StackPush(&ps, 1);
StackPush(&ps, 1);
while (!StackEmpty)
{
printf("%d\n", StackTop(&ps));
StackPop(&ps);
}
return 0;
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧