问题描述
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
struct Stack {
int top;
unsigned capacity;
int* array;
};
struct Stack* createStack(unsigned capacity)
{
struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack));
stack->capacity = capacity;
stack->top = -1;
stack->array = (int*)malloc(stack->capacity * sizeof(int));
return stack;
}
int isFull(struct Stack* stack)
{
return stack->top == stack->capacity - 1;
}
int isEmpty(struct Stack* stack)
{
return stack->top == -1;
}
void push(struct Stack* stack,int item)
{
if (isFull(stack))
return;
stack->array[++stack->top] = item;
printf("%d pushed to stackn",item);
}
int pop(struct Stack* stack)
{
if (isEmpty(stack))
return INT_MIN;
return stack->array[stack->top--];
}
int peek(struct Stack* stack)
{
if (isEmpty(stack))
return INT_MIN;
return stack->array[stack->top];
}
int main()
{
struct Stack* stack = createStack(100);
push(stack,11);
push(stack,12);
push(stack,33);
printf("%d popped from stackn",pop(stack));
return 0;
}
我在网上找到了这个堆栈实现程序,有一个没有数据类型“无符号容量”的变量。那是什么意思? 我运行了代码,它工作正常。 无符号容量存储什么数据类型值?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)