{"id":19878855,"url":"https://github.com/jakubkorytko/custom-stack","last_synced_at":"2025-03-01T02:34:07.624Z","repository":{"id":206489682,"uuid":"674808270","full_name":"JakubKorytko/custom-stack","owner":"JakubKorytko","description":"Versatile project that allows dynamic stack creation for any data type without arrays, enhanced for ease of use and adding of new types","archived":false,"fork":false,"pushed_at":"2023-11-24T17:03:00.000Z","size":498,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T17:49:14.683Z","etag":null,"topics":["mit-license","open-source","stack-implementation","visual-studio"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JakubKorytko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-04T20:48:23.000Z","updated_at":"2023-11-24T17:09:13.000Z","dependencies_parsed_at":"2025-01-11T17:46:37.543Z","dependency_job_id":"c4d03300-0c99-4278-bb5d-29f5b4dc17b4","html_url":"https://github.com/JakubKorytko/custom-stack","commit_stats":null,"previous_names":["jakubkorytko/custom-stack"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakubKorytko%2Fcustom-stack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakubKorytko%2Fcustom-stack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakubKorytko%2Fcustom-stack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakubKorytko%2Fcustom-stack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JakubKorytko","download_url":"https://codeload.github.com/JakubKorytko/custom-stack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241309093,"owners_count":19941722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mit-license","open-source","stack-implementation","visual-studio"],"created_at":"2024-11-12T17:06:53.102Z","updated_at":"2025-03-01T02:34:07.597Z","avatar_url":"https://github.com/JakubKorytko.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom Stack\n\n[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](LICENSE)\n![Visual Studio](https://img.shields.io/badge/Visual%20Studio-5C2D91.svg?style=for-the-badge\u0026logo=visual-studio\u0026logoColor=white)\n![C](https://img.shields.io/badge/c-%2300599C.svg?style=for-the-badge\u0026logo=c\u0026logoColor=white)\n\n[![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/)\n[![Run Super-Linter](https://github.com/JakubKorytko/custom-stack/actions/workflows/super-linter.yml/badge.svg)](https://github.com/JakubKorytko/custom-stack/actions/workflows/super-linter.yml)\n\n## Table of Contents\n\n- [Custom Stack](#custom-stack)\n  - [Table of Contents](#table-of-contents)\n  - [Introduction](#introduction)\n  - [Prerequisites](#prerequisites)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Menu](#menu)\n    - [Actions](#actions)\n  - [Changing the data type used in the stack](#changing-the-data-type-used-in-the-stack)\n    - [Before you start](#before-you-start)\n    - [Steps](#steps)\n  - [Why is this an application and not a library?](#why-is-this-an-application-and-not-a-library)\n  - [Contributing](#contributing)\n  - [Contact](#contact)\n  - [License](#license)\n\n## Introduction\n\nThis project is a custom stack implementation in C using the Visual Studio 2022.\nIt allows you to create a stack of any data type you want.\nIt is also possible to add multiple data types and switch between them.\nWhat is unique about this stack is that **it is implemented without using array for the stack elements**.\nInstead, it uses a pointer to the previous element in the stack and a pointer to the top element.\nThis allows you to create a stack of any size you want without having to allocate a large array for the stack elements.\n\nAlthough this project is based on the [instructions](./docs/Instructions.pdf) located in the [docs](./docs/) directory,\nit has been extended with additional features to make it more user-friendly and to make it easier to add new data types.\n\nThere are some Visual Studio specific configurations in the project,\nif you plan to use this project in another IDE or extend it,\nsee the [before you start](#before-you-start) section (the first two points).\n\n**This project was created targeting Windows. It has not been tested on other operating systems.**\n\n## Prerequisites\n\nBefore using the Custom Stack, make sure that you have the following prerequisites installed on your system:\n\n- [Visual Studio 2022 (version 17.6.3 or later)](https://visualstudio.microsoft.com/vs/)\n  - \"Desktop development with C++\" workload installed.\n\n## Installation\n\n1. Clone this repository to your local machine using Git,\nor download the ZIP file and extract it to a directory of your choice:\n\n    ```bash\n    git clone https://github.com/JakubKorytko/custom-stack.git\n    ```\n\n1. Change to the project directory:\n\n    ```bash\n    cd custom-stack\n    ```\n\n1. Open the `custom-stack.sln` solution file in Visual Studio.\n\n1. Build or run the project in Visual Studio:\n\n    - **Run the project** in the Visual Studio\n      - `F5` /  `Ctrl + F5` by default\n      - or `Debug` -\u003e `Start Debugging` / `Start Without Debugging` on the toolbar\n\n    - or **Build project** executable\n      - `Ctrl + B` / `Ctrl + Shift + B` by default\n      - or `Build` -\u003e `Build Solution` / `Build custom_stack` on the toolbar\n\n    The executable will be available in the `build` directory in both cases.\n\n## Usage\n\nAfter running the project, you will be presented with the menu.\n\n### Menu\n\nThe application has an interactive menu that allows you to use the stack.\nIt takes input (number) from the user and performs the corresponding action.\nThe menu is displayed after each action.\n\n### Actions\n\nThe following actions are available (9 in total):\n\n- **Push** (0) - adds an element to the stack\n- **Pop** (1) - removes an element from the stack and prints it\n- **Print stack** (2) - prints all elements in the stack\n- **Print top element** (3) - prints the top element of the stack\n- **Find** (4) -  searches for an element in the stack based on the search data provided by the user\n- **Save to disk** (5) - saves the stack to a file\n- **Read from disk** (6) - reads the stack from a file\n- **Clear** (7) - clears the stack\n- **Finish** (8) - exit the application\n\n*There are plans to add an option to change the data type\nused in the stack directly from the menu but this is not implemented yet.*\n\n## Changing the data type used in the stack\n\n### Before you start\n\n- Additional Include Directories (`Project -\u003e Properties -\u003e Configuration Properties -\u003e C/C++ -\u003e General -\u003e Additional Include Directories`) are used in the project. Precisely:\n  - `$(SolutionDir)src` ([src](./src/) directory)\n  - `$(SolutionDir)data` ([data](./data/) directory)\n  - `$(SolutionDir)config` ([config](./config/) directory)\n  - `$(SolutionDir)` ([root](./) directory)\n- This project uses precompiled headers,\nso for each `.c` file you need to include the `pch_source/stdafx.h` header.\nCheck the [src/pch_source/stdafx.h](./src/pch_source/stdafx.h) file to see which headers are included in the precompiled headers. You can also add your own headers there.\n- In the steps below, replace `CUSTOM_DATA_TYPE` or `custom_data_type` in the names of the files, functions or variables with the name of the new data type.\n- You can add as many data types as you like, but only one at a time can be used by the stack.\n- If any step is unclear, check the `MY_STUDENT` data type implementation for reference.\n\n### Steps\n\n1. Add new data type to the `MY_DATA_TYPE` enum in the [config/general_config.h](./config/general_config.h) file (`Config -\u003e General -\u003e general_config.h` in the Visual Studio Solution Explorer):\n\n    ```c\n    enum MY_DATA_TYPE {\n        // ...\n        DATA_TYPE__CUSTOM_DATA_TYPE,\n        // ...\n\n        DATA_TYPE__TOTAL\n    };\n    ```\n\n    Remember to add the new data type before the `DATA_TYPE__TOTAL` element.\n\n1. Add the directory containing the logic for the new data type to the project in the [data](./data/) folder\n(you can of course add it in the Visual Studio Solution Explorer, but it will be created in the [vcx](./vcx/) directory,\nso to keep the project clean,\nyou should create the files manually in the [data](./data/) folder and then add them to the project in the `Data` filter).\nIt can contain anything but it must export the following functions\n(names are not important, just match the return type and the arguments):\n\n    ```c\n\n    // function that handles printing the element data\n    void CUSTOM_DATA_TYPE_Print(void *ptr);\n\n    // function to free the memory allocated for the data\n    void CUSTOM_DATA_TYPE_Free(void *ptr);\n\n    // function that saves the element data to a file\n    int CUSTOM_DATA_TYPE_Save(void **pdat, FILE *pf);\n\n    // function to read element data from a file\n    int CUSTOM_DATA_TYPE_Read(void **pdat, FILE *pf);\n\n    // function that returns a pointer to the element\n    // that should be pushed to the stack\n    void *CUSTOM_DATA_TYPE_Push();\n\n    // function that compares two elements\n    // should return 1 if the elements are equal\n    // and 0 otherwise\n    int CUSTOM_DATA_TYPE_Compare(void *pCurData, void *pSearchData);\n\n    // function that takes input from the user\n    // and returns a pointer to the data to search for\n    void *CUSTOM_DATA_TYPE_SearchData();\n\n    // function that releases the memory allocated for the search data\n    void CUSTOM_DATA_TYPE_SearchData_Free(void *searchDat);\n\n    // function that returns the data type of the element\n    // MY_DATA_TYPE is an enum defined in general_config.h\n    // it is available in the whole project\n    // thanks to the pre-compiled headers\n    enum MY_DATA_TYPE CUSTOM_DATA_TYPE_GetType();\n    ```\n\n1. Create a new pair of files in the [config](./config/) folder (you can of course add them in the Visual Studio Solution Explorer, but they will be created in the [vcx](./vcx/) directory, so to keep the project clean, you should manually create the files in the [config](./config/) folder and then add them to the project in the `Config` filter):\n\n    - `custom_data_type_config.c`\n    - `custom_data_type_config.h`\n\n1. If you need to use output messages, you can use the following function:\n\n    ```c\n    output(enum CUSTOM_MESSAGES message)\n    ```\n\n    To use it, add the enum (to the CUSTOM_MESSAGES enum in the [config/general_config.h](./config/general_config.h)) and string (to the custom_messages array in the [config/general_config.c](./config/general_config.c)) pairs for the new data type. Then you can use the function like this:\n\n    ```c\n    output(MESSAGE__CUSTOM_DATA_TYPE__SOME_MESSAGE);\n    ```\n\n    To keep the code clean, you can define the macros for the enum and the array in the `config/custom_data_type_config.h` file and then include them in the [config/general_config.h](./config/general_config.h) and [config/general_config.c](./config/general_config.c) files (see [config/student_config.h](./config/student_config.h) for a reference)\n\n1. Include following headers in `custom_data_type_config.c`:\n\n    ```c\n\n    #include \"pch_source/stdafx.h\"\n    #include \"data_type_config.h\"\n    #include \"data_type/data_type.h\"\n    ```\n\n1. Add the following structure to `custom_data_type_config.c`:\n\n    ```c\n    struct MY_DATA_POINTERS CUSTOM_DATA_TYPE__POINTERS = {\n        .type = DATA_TYPE__CUSTOM_DATA_TYPE,\n        .fun_print = CUSTOM_DATA_TYPE_Print,\n        .fun_free = CUSTOM_DATA_TYPE_Free,\n        .fun_save = CUSTOM_DATA_TYPE_Save,\n        .fun_read = CUSTOM_DATA_TYPE_Read,\n        .fun_push = CUSTOM_DATA_TYPE_Push,\n        .fun_comp = CUSTOM_DATA_TYPE_Compare,\n        .fun_search_data = CUSTOM_DATA_TYPE_SearchData,\n        .fun_free_search_data = CUSTOM_DATA_TYPE_SearchData_Free,\n        .fun_get_type = CUSTOM_DATA_TYPE_GetType\n    }\n\n1. Finally, add the reference to the `CUSTOM_DATA_TYPE__POINTERS` structure to the `MY_DATA_POINTERS_ARRAY` array in the `custom_data_type_config.c`:\n\n    ```c\n    const struct MY_DATA_POINTERS *MY_DATA_POINTERS_ARRAY[DATA_TYPE__TOTAL] = {\n        // ...\n        \u0026CUSTOM_DATA_TYPE__POINTERS,\n        // ...\n    }\n    ```\n\n    And set the `const enum MY_DATA_TYPE interface_type` variable to the new data type:\n\n    ```c\n    const enum MY_DATA_TYPE interface_type = DATA_TYPE__CUSTOM_DATA_TYPE;\n    ```\n\n## Why is this an application and not a library?\n\nI'm aware that this project could be implemented as a library because it makes more sense, and I plan to do so in the future. However, I decided to implement it as an app for now because I'm not familiar with the library implementation in C and I wanted to focus on the stack implementation itself.\n\nFeel free to make a pull request if you want to implement it as a library. I will be happy to merge it.\n\n## Contributing\n\nIf you find issues or have suggestions for improvements,\nfeel free to open an issue or submit a pull request.\nContributions are welcome!\n\n## Contact\n\nIf you have any questions, feel free to contact me at \u003cjakub@korytko.me\u003e.\n\n## License\n\nThis project is released under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubkorytko%2Fcustom-stack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakubkorytko%2Fcustom-stack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubkorytko%2Fcustom-stack/lists"}