Skip to content

Instantly share code, notes, and snippets.



Created Mar 16, 2020
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;
typedef struct stackList {
Stack *top;
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;
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