Skip to content

AnkitNeupane007/Dynamic-Array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dynamic Array in C++

Overview

This C++ project implements a dynamic array class (DynamicArray) that allows for dynamic resizing and various operations commonly associated with arrays.

Features

  • Dynamic Sizing: Automatically adjusts its size to accommodate new elements.
  • Element Addition: Supports adding single elements or multiple elements at once.
  • Element Removal: Provides functionality to remove specific elements.
  • Index Access: Allows accessing elements using array indexing ([] operator overloading).
  • Memory Management: Efficiently manages memory by resizing when necessary and deallocating memory when elements are removed.

Usage

Initialization

To use the DynamicArray class, first include the dynamic_array.h in your program. Then initialize it with an initial size:

#include "dynamic_array.h"
DynamicArray<int> arr(3); // Initializes an integer array with a size of 3

Adding elements

// We can add a single element
arr.add_element(1);
// Or we can use { } to pass multiple elements at once
arr.add_element({97, 2, 3, 3});

Displaying elements

// Displays all the elements
arr.display_element();

Displaying current size of array

// This returns the size of the array and the number of elements in it
arr.return_size();

Removing elements

If there are two or more same numbers, it removes the last one.

// This removes the number specified
arr.pop_element(3);

Viewing indexed elements

Returns the value of array in index specified inside square brackets [index]

cout << arr[0] << endl; // Returns 1 if you have followed the previous steps

About

This is an implementaion of a dynamic array in C++.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages