I have written some code to remove duplicates from Integer Array. I dont want to use any inbuilt keywords/property.
Here is my logic :
int[] iArray = {1,2,3,2,3,4,3};
int t = 0;
int arraysize = iArray.Length;
for (int m = 0; m < arraysize; m++)
{
if (iArray[m] != iArray[t])
{
t++;
iArray[t] = iArray[m];
}
}
arraysize = t + 1;
for (int m = 0; m < arraysize; m++)
{
Console.WriteLine(iArray[m]);
}
Output should be:
1,2,3,4
It does not give the desired output. Guys, this is not the homewok. This is Self Learning. No LINQ,Contains keyword please. Thank you for you replies.
Thanks.
We can remove duplicate element in an array by 2 ways: using temporary array or using separate index. To remove the duplicate element from array, the array must be in sorted order. If array is not sorted, you can sort it by calling Arrays. sort(arr) method.
Since this is a homework, I would not fix your code, and give you a few notes instead:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With