Skip to content

jasiukiewicztymon/Dynamic_Array.cs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Dynamic_Array.cs

Dynamics arrays are array which size is not fixed, you can add value on front, back and use some functions to make your code project easier

Before start

First to use the dynamic array download the .cs file and add it to your C# project Add the using part to enemble dynamics arrays in your project

using DynamicArray;

Array creation

To create an dynamic array use the next C# line

DynamicArray<type> array = new DynamicArray<type>(size);

< type > : the type is the type of values inside the array
array : is the array name
size : is the default size in int type, if you don't know what size you need use 0 as a empty array

Array functions

  1. Push_front and push_back functions
    array.PushFront(value1);
    Add the value1 at the front of the array

    array.PushBack(value2);
    Add the value2 at the back of the array

  2. Insert function
    array.Insert(index, value);
    Set the value at index index for value

    array.Insert(-1, value);
    Set the value at the last index for value

  3. Size property and clear functions
    array.Size;
    Return the size of the array

    array.Clear();
    Reset the array to size 0 and erase all values

  4. Remove functions
    array.Remove(index);
    Erase the value at the index from the array

    array.Remove(indexstart, indexend);
    Erase all values from indexstart to indexend, including the values at indexstart and indexend

    array.Remove(indexstart, -1);
    Erase all values from indexstart to the end of the array, including the values at indexstart and the last value

  5. At functions
    array.At(index);
    Return the value at the index

  6. Fill functions
    array.Fill(indexstart, indexend, value);
    Replace all index in array from indexstart to indexend by the value, including the indexstart and indexend

  7. Copy and sort functions
    array.Copy(array2);
    Copy the array2 to the array

    array.Sort();
    Sort the array

  8. Reverse functions
    array.Reverse();
    Return the reversed array

  9. Find functions
    array.Find(value);
    Return the first index of the value

  10. Add functions
    array.Add(array2);
    Add the array2 to the array

Code example

using System;
using DynamicArray;

namespace Test
{
    internal class Program
    {
        static void Main(string[] args)
        {
            DynamicArray<int> array = new DynamicArray<int>(5);
            for (int i = 0; i < array.Size; i++)
                array.Insert(i, i);

            DynamicArray<int> array2 = new DynamicArray<int>(0);
            array2.Copy(array);
            array2.Add(array);

            array2.Sort();
            array2.Reverse();
            array2.Remove(6, -1);
            array2.Fill(0, 1, -3);
            array2.PushFront(-10);
            array2.PushBack(100);
            int index = array2.Find(-3);

            Console.WriteLine(index);
            for (int i = 0; i < array2.Size; i++)
            {
                Console.WriteLine(array2.At(i));
            }

            array2.Clear();
            Console.WriteLine(array2.Size);

            Console.ReadKey();
        }
    }
}


OUTPUT:

1
-10
-3
-3
3
3
2
2
100
0

License

The MIT License

License: MIT

Releases

No releases published

Packages

No packages published

Languages