Hi,
I received one question "How to delete duplicate entries from an array" Constrain: No new data structure and same array should return only distinct element. So for example If my array is 1,3,3,3,5,55,67,1 then the result should be 1,3,5,55,67
I have solved the problem
public void DeleteDuplicate(int[] array)
{
int l = 0;
int newPosition = array.Length -1;
for (int i = 0; i < array.Length; i++)
{
for (int j = i + 1; j < array.Length-l; j++)
{
if (array[i] == array[j])
{
int temp = array[j];
array[j] = array[newPosition];
array[newPosition] = temp;
newPosition--;
l++;
}
}
}
Array.Resize(ref array, array.Length - l);
}
I need your opinion whether it is a good algorithm or need to change something.
Thanks, Pritam