#include <stdio.h>
#include <stdlib.h>
struct Node {
char value;
struct Node *next;
};
struct Stack {
struct Node *head;
int size;
};
struct Stack *createStack() {
struct Stack *s = malloc(sizeof(struct Stack));
s->head = NULL;
s->size = 0;
return s;
}
void push(struct Stack *s, char value) {
struct Node *newNode = malloc(sizeof(struct Node));
newNode->value = value;
newNode->next = s->head;
s->head = newNode;
s->size++;
}
char pop(struct Stack *s) {
if (s->size == 0) {
return ' ';
}
struct Node *popped = s->head;
s->head = s->head->next;
char poppedValue = popped->value;
free(popped);
s->size--;
return poppedValue;
}
char peek(struct Stack *s) {
if (s->size == 0) {
return ' ';
}
return s->head->value;