A C++ template-based dynamic array implementation with powerful functionalities for managing elements efficiently. π
The clsDynamicArray class is a generic dynamic array implementation in C++ that supports resizing, modifications, and element manipulations. It provides a flexible way to manage collections of data with dynamic memory allocation, ensuring optimal performance and usability.
- Insert elements at any position β
- Delete elements efficiently β
- Resize dynamically to manage memory β»οΈ
- Reverse the entire array order π
- Find & Modify elements easily π
- Clear the array in one call β¨
This implementation leverages C++ templates, making it compatible with any data type.
SetItem(Index, Value): Updates the element at a specific index.GetItem(Index): Retrieves the element at a given index.Size(): Returns the total number of elements in the array.IsEmpty(): Checks if the array is empty.PrintList(): Displays all elements in the array.
Resize(New_Size): Adjusts the size of the array dynamically.Reverse(): Reverses the order of elements.Clear(): Removes all elements and frees memory.Find(Value): Returns the index of the first occurrence of a value (-1 if not found).DeleteItem(Value): Deletes the first occurrence of a given value.DeleteItemAt(Index): Deletes the element at a specific index.DeleteFirstItem(): Removes the first element.DeleteLastItem(): Removes the last element.InsertAt(Index, Value): Inserts an element at a specified position.InsertAtBeginning(Value): Inserts an element at the start.InsertAtEnd(Value): Inserts an element at the end.InsertBefore(Index, Value): Inserts an element before a given index.InsertAfter(Index, Value): Inserts an element after a given index.
- Use
InsertAt(Index, Value)to place an element at a specific position. DeleteItemAt(Index)removes an element from a given index.DeleteFirstItem()andDeleteLastItem()handle edge cases.
Resize(New_Size)adjusts the capacity dynamically, ensuring optimal usage.Clear()safely deletes all elements to prevent memory leaks.
Find(Value)locates elements efficiently.SetItem(Index, Value)allows modifying elements dynamically.
- π’ Iterator Support: Enabling STL-like traversal.
- β Performance Optimization: Enhancing efficiency for large datasets.
- πΎ Persistent Storage: Implementing file-based data storage.
- β Thread Safety: Supporting concurrent operations.
- Language: C++
- Templates: Supports multiple data types.
- Dynamic Memory Allocation: Utilizes heap memory efficiently.
This project demonstrates:
- β Dynamic memory management with pointers
- β Efficient array operations (insert, delete, find, modify)
- β Generic programming using C++ templates
This project is open-source. Feel free to modify and enhance it! π
Contributions are welcome! If you have ideas for improvements, submit a Pull Request.
- Download the repository.
- Include
clsDynamicArray.hin your project. - Compile & Run your C++ program with a standard compiler (e.g.,
g++ main.cpp -o output). - Test various array operations.