-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayOperation.cs
34 lines (33 loc) · 966 Bytes
/
ArrayOperation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DSA
{
class ArrayOperation
{
public static int[] Insert(int numberToInsert, int location, int[] arr)
{
int[] arrN = new int[arr.Length + 1];
for (int i = 0; i < location; i++)
{
arrN[i] = arr[i];
}
for (int i = arrN.Length - 1; i > location; i--)
{
arrN[i] = arr[i - 1];
}
arrN[location] = numberToInsert;
for (int i = 0; i < arrN.Length; i++)
{
Console.WriteLine("\nThe new Array is :" + arrN[i]);
}
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine("\nThe old array insertion is :" + arr[i]);
}
return arr;
}
}
}