Skip to content

About

A C++ template-based dynamic array class (clsDynamicArray) that supports efficient insertion, deletion, resizing, and searching for elements of any data type.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

📌 Dynamic Array Implementation (clsDynamicArray) ⚡

A C++ template-based dynamic array class that provides powerful and efficient tools to manage elements dynamically. 🚀


🌟 Project Overview

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.


🔹 Core Functionalities:

✅ 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.


✨ Features

🔹 Basic Operations

  • 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.

🔹 Advanced Functionalities

  • 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.

🚀 How It Works

🔹 Insertion & Deletion

  • Use InsertAt(Index, Value) to insert at any valid position.
  • Use DeleteItemAt(Index) to remove specific elements.
  • DeleteFirstItem() and DeleteLastItem() manage front/back deletions.

🔹 Resizing & Memory Management

  • Resize(NewSize) adjusts memory allocation dynamically.
  • Clear() safely deletes the internal array and resets size.

🔹 Searching & Modifications

  • Find(Value) performs a linear search for the value.
  • SetItem(Index, Value) allows for safe value assignment with bounds checking.

📚 Potential Enhancements

💡 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


⚙️ Technologies Used

  • Language: C++
  • Paradigm: Generic Programming (Templates)
  • Memory: Dynamic Allocation (Heap)

🎯 Learning Outcomes

  • ✅ 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

🌟 License

This project is open-source. Feel free to modify, enhance, and use it in your own projects! 🚀


🤝 Contributing

Contributions are welcome! If you find a bug or have a feature request, feel free to open an issue or submit a pull request.


🚀 How to Run

  1. Clone or Download the repository
  2. Include clsDynamicArray.h in your project
  3. Create a main.cpp to 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;
}
  1. Compile and Run:
g++ main.cpp -o MyApp
./MyApp

About

A C++ template-based dynamic array class (clsDynamicArray) that supports efficient insertion, deletion, resizing, and searching for elements of any data type.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages