Created
March 16, 2020 04:52
-
-
Save tiger1710/650d50b6eef980e62ab68d63c7628016 to your computer and use it in GitHub Desktop.
c-style stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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