Skip to content

Instantly share code, notes, and snippets.

@tiger1710 tiger1710/myStack.c
Created Mar 16, 2020

Embed
What would you like to do?
c-style stack
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
typedef struct stack {
char data;
struct stack *next;
}Stack;
typedef struct stackList {
Stack *top;
}sList;
void initStack(sList *list) {
list->top = NULL;
}
void push(sList *list, char data) {
Stack *new = (Stack*)malloc(sizeof(Stack));
new->data = data;
new->next = list->top;
list->top = new;
}
char peek(sList *list) {
return list->top->data;
}
void pop(sList *list) {
Stack *temp = list->top->next;
free(list->top);
list->top = temp;
}
bool isEmpty(sList *list) {
if (list->top == NULL) return true;
else return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.