// C program for array implementation of stack // adapted from https://www.geeksforgeeks.org/stack-data-structure-introduction-program/ #include #include #include #include #define MAX_VALUES 10 #define MAX_LENGTH 25 // A structure to represent a stack typedef struct { int top; int capacity; char *array[MAX_VALUES]; } stack; // Function prototypes stack *create_stack(int capacity); bool is_full(stack *stack); int is_empty(stack *stack); char *pop(stack *stack); void push(stack *stack, char *item); // Jack creates a stack int main(void) { stack *stack = create_stack(MAX_VALUES); if (stack == NULL) { printf("Could not create stack.\n"); } push(stack, "Blue Shirt"); push(stack, "Green Shirt"); push(stack, "Red Shirt"); push(stack, "White Shirt"); // Add your own elements to the stack while (true) { char *item = get_string("Enter an item of clothing to add to the stack: "); // Exit loop if nothing entered if (strlen(item) == 0) { break; } push(stack, item); } char *popped = pop(stack); if (!popped) { printf("The stack is empty\n"); } else { printf("%s popped from stack\n", popped); } return 0; } // Function to create a stack of MAX_VALUES capacity. stack *create_stack(int capacity) { // Check capacity if (capacity < 1 || capacity > MAX_VALUES) { return NULL; } stack *stack = malloc(sizeof(stack)); if (stack == NULL) { return NULL; } stack->capacity = capacity; stack->top = -1; return stack; } // Stack is full when top is equal to the last index bool is_full(stack *stack) { return stack->top == stack->capacity - 1; } // Stack is empty when top is equal to -1 int is_empty(stack *stack) { return stack->top == -1; } // Function to remove an item from stack. It decreases top by 1 char *pop(stack *stack) { // TODO return NULL; } // Function to add an item to stack. It increases top by 1 void push(stack *stack, char *item) { // TODO }