A C++ template-based dynamic array class that provides powerful and efficient tools to manage elements dynamically. 🚀
The clsDynamicArray class is a generic, reusable C++ implementation of a dynamic array using templates. It supports all core array operations, including inserting, deleting, resizing, reversing, and searching, while ensuring type flexibility and efficient memory management.
✅ Insert elements at any position
✅ Delete elements by index or value
✅ Resize dynamically to manage memory efficiently
✅ Reverse array order
✅ Search and update elements easily
✅ Clear all elements in one call
This implementation uses C++ templates, making it compatible with any data type: int, float, string, custom classes, etc.
SetItem(Index, Value): Update value at a specific index.GetItem(Index): Retrieve value at a specific index.Size(): Return the current array size.IsEmpty(): Check if the array is empty.PrintList(): Display all elements in the array.
Resize(NewSize): Resize the array while preserving data.Reverse(): Reverse the element order.Clear(): Clear all elements and free memory.Find(Value): Find the index of a value (returns -1 if not found).DeleteItem(Value): Delete the first occurrence of a value.DeleteItemAt(Index): Delete element at a given index.DeleteFirstItem(): Remove the first element.DeleteLastItem(): Remove the last element.InsertAt(Index, Value): Insert an element at a specified position.InsertAtBeginning(Value): Insert at the beginning of the array.InsertAtEnd(Value): Append an element to the end.InsertBefore(Index, Value): Insert before a given index.InsertAfter(Index, Value): Insert after a given index.
- Use
InsertAt(Index, Value)to insert at any valid position. - Use
DeleteItemAt(Index)to remove specific elements. DeleteFirstItem()andDeleteLastItem()manage front/back deletions.
Resize(NewSize)adjusts memory allocation dynamically.Clear()safely deletes the internal array and resets size.
Find(Value)performs a linear search for the value.SetItem(Index, Value)allows for safe value assignment with bounds checking.
💡 Iterator Support – Enable range-based for loops and STL-style access
⚡ Performance Optimization – Enhance efficiency for large datasets
💾 Persistent Storage – Save/load array to/from files
🛡️ Thread Safety – Ensure safe access in multi-threaded environments
- Language: C++
- Paradigm: Generic Programming (Templates)
- Memory: Dynamic Allocation (Heap)
- ✅ Mastery of dynamic memory and pointer management
- ✅ Understanding of C++ templates and reusable components
- ✅ Implementation of core data structure operations
- ✅ Practice with safe array access and memory cleanup
This project is open-source. Feel free to modify, enhance, and use it in your own projects! 🚀
Contributions are welcome! If you find a bug or have a feature request, feel free to open an issue or submit a pull request.
- Clone or Download the repository
- Include
clsDynamicArray.hin your project - Create a
main.cppto test your functionality:
#include <iostream>
#include "clsDynamicArray.h"
int main() {
clsDynamicArray<int> arr(3);
arr.SetItem(0, 10);
arr.SetItem(1, 20);
arr.SetItem(2, 30);
arr.InsertAtEnd(40);
arr.PrintList(); // Output: 10 20 30 40
return 0;
}- Compile and Run:
g++ main.cpp -o MyApp
./MyApp