“无符号容量”是什么意思?

时间:2021-05-29 06:53:43

标签: c data-structures stack

#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;
}

我在网上找到了这个堆栈实现程序,有一个没有数据类型“无符号容量”的变量。那是什么意思? 我运行了代码,它工作正常。 无符号容量存储什么数据类型值?

0 个答案:

没有答案
相关问题