So the method remove removes only the first occurrence of an element. I am supposed to Add the method
removeAll() that will remove all occurrences of a given element. I have tried many different things but nothing has worked.
using System;
namespace UnorderedArrayListNamespace
{
public class UnorderedArrayList
{
protected int[] list;
protected int next;
public UnorderedArrayList()
{
list = new int[100];
next = 0;
}
public void insert(ref int item)
{
list[next] = item;
next++;
}
public void remove(ref int item)
{
if (next == 0)
{
}
else
{
//find value, if it exists
for (int i = 0; i > next; i++)
{
if (item.Equals(list[i]))
{
for (int j = i; j < next; j++) list[j] = list[j + 1];
next--;
break;
}
}
}
}
public void print()
{
for (int i = 0; i < next; i++)
{
Console.WriteLine(list[i]);
}
Console.WriteLine();
}
}
}