Question
Complete the following code in C# and include the following: isEmpty(), isFull(), size(), printAll(), addBack(value), add(value), addFront(value), insert(index), deleteBack(), deleteFront(), delete(index), contains(value), clear(), sort() using
Complete the following code in C# and include the following: isEmpty(), isFull(), size(), printAll(), addBack(value), add(value), addFront(value), insert(index), deleteBack(), deleteFront(), delete(index), contains(value), clear(), sort()
using System;
namespace 2342342
{
class MList
{
private int[] arr;
private int MaxSize;
private int LastElementList = 0;
public MyList(int size)
{
arr = new int[size];
MaxSize = size;
}
public int GetMaxSize()
{
return arr.Length;
}
public void addBack(int value)
{
if (LastElementList == MaxSize)
{
Console.WriteLine("Array is full. Can not add to the list");
}
else
{
arr[LastElementList] = value;
LastElementList++;
}
}
public void printAll()
{
for (int i=0; i< LastElementList; i++)
{
Console.WriteLine(arr[i] + ",");
}
}
}
class Program
{
static void Main()
{
MList arrlist = new MList(50);
int max = arrlist.GetMaxSize();
arrlist.addBack(1);
arrlist.addBack(2);
arrlist.printAll();
Console.WriteLine("My ArrayList has a max of {0} elements", max);
Console.ReadLine();
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started