DynamicArray
This library implements a std::vector like Dynamic Array data structure in C, allowing for the creation, modification, and manipulation of an array whose size can be dynamically adjusted during runtime.
Install / Use
/learn @farukalpay/DynamicArrayREADME
📝 Documentation
Documentation can be found on the following link
⚙️ Introduction
This library implements a std::vector like Dynamic Array data structure in C, allowing for the creation, modification, and manipulation of an array whose size can be dynamically adjusted during runtime. Dynamic array is similar to the standard array in C, but it can grow or shrink in size as needed.
⚒️ Getting Started
Download the repository and copy the library your local project folder (say, ./myproject)
git clone https://github.com/farukalpay/DynamicArray.git
cp DynamicArray.h ./myproject
Import DynamicArray.h and get started
#include DynamicArray.h
Example usage is shown below
#include <stdio.h>
#include "DynamicArray.h"
// Structure for a person
typedef struct {
char name[50];
int age;
} Person;
int main() {
DynamicArray personArray;
initDynamicArray(&personArray, sizeof(Person));
// Create some Person objects
Person person1 = { "Alice", 25 };
Person person2 = { "Bob", 30 };
Person person3 = { "Charlie", 35 };
// Push the Person objects into the DynamicArray
pushBack(&personArray, &person1);
pushBack(&personArray, &person2);
pushBack(&personArray, &person3);
// Get and print the elements in the DynamicArray
printf("-- Elements Before Update --\n");
size_t numPersons = personArray.size;
for (size_t i = 0; i < numPersons; i++) {
Person* person = (Person*)getElementAt(&personArray, i);
printf("Name: %s, Age: %d\n", person->name, person->age);
}
// Pop an element from the back of the DynamicArray
popBack(&personArray);
// Resize the DynamicArray
resize(&personArray, 2);
// Create a new DynamicArray
DynamicArray newPersonArray;
initDynamicArray(&newPersonArray, sizeof(Person));
// Create another Person object
Person person4 = { "David", 40 };
// Push the Person object into the new DynamicArray
pushBack(&newPersonArray, &person4);
// Concatenate the new DynamicArray with the original DynamicArray
concatenate(&personArray, &newPersonArray);
// Get and print the updated elements in the DynamicArray
printf("-- Elements After Update --\n");
numPersons = personArray.size;
for (size_t i = 0; i < numPersons; i++) {
Person* person = (Person*)getElementAt(&personArray, i);
printf("Name: %s, Age: %d\n", person->name, person->age);
}
// Clear the DynamicArray
clearDynamicArray(&personArray);
return 0;
}
Output is shown below
-- Elements Before Update --
Name: Alice, Age: 25
Name: Bob, Age: 30
Name: Charlie, Age: 35
-- Elements After Update --
Name: Alice, Age: 25
Name: Bob, Age: 30
Name: David, Age: 40
🆘 Support
If you find any errors, mistakes please feel free to submit a pull request. If you would like to reach me, you can send me an e-mail via faruk.1alpayu@gmail.com
Related Skills
YC-Killer
2.7kA library of enterprise-grade AI agents designed to democratize artificial intelligence and provide free, open-source alternatives to overvalued Y Combinator startups. If you are excited about democratizing AI access & AI agents, please star ⭐️ this repository and use the link in the readme to join our open source AI research team.
groundhog
398Groundhog's primary purpose is to teach people how Cursor and all these other coding agents work under the hood. If you understand how these coding assistants work from first principles, then you can drive these tools harder (or perhaps make your own!).
last30days-skill
13.8kAI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
000-main-rules
Project Context - Name: Interactive Developer Portfolio - Stack: Next.js (App Router), TypeScript, React, Tailwind CSS, Three.js - Architecture: Component-driven UI with a strict separation of conce
