Skip to content

Instantly share code, notes, and snippets.

@tiger1710
Created March 16, 2020 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiger1710/650d50b6eef980e62ab68d63c7628016 to your computer and use it in GitHub Desktop.
Save tiger1710/650d50b6eef980e62ab68d63c7628016 to your computer and use it in GitHub Desktop.
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