Skip to content

K4zoku/c-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

c-stack

Workflow Status License

💡 About

This is an implementation of a std::stack, but in plain C89 code.

This repo is inspired by c-vector

Memory structure

┏━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃ size ┃ capacity ┃ data... ┃
┗━━━━━━┻━━━━━━━━━━┻━━━━━━━━━┛
                  ↑ user's pointer

📜 Example usage

#define CSTACK_LOGARITHMIC_GROWTH
#include <stdio.h>
#include "cstack.h"

int main(int argc, char ** argv) {
    (void) argc;
    (void) argv;
    const char str[] = "abcdefgh";
    cstack_type(char) rev = cstack_new();
    size_t i;
    for (i = 0; str[i] != '\0'; ++i) {
        cstack_push(rev, str[i]);
    }

    printf("size: %lu\n", cstack_size(rev));

    while (!cstack_empty(rev)) {
        putchar(cstack_top(rev));
        cstack_pop(rev);
    }
    putchar('\n');

    cstack_free(rev);
    return 0;
}


Made with ❤️ by @K4zoku

About

A stack implementation in C similar to the one found in standard C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published