问题描述
如何在不使用任何集合和Linq的情况下在C#中实现集补和集差?
我们有两个数组:
int [] arr1 = new int { 1,2,3,4};
int[] arr2 = new int {3,4,5,6,7,8};
补码必须为:arr3 {5,8}
,而差必须为:arr4 {1,2}
。
我尝试过将一组添加到另一组,然后找到重复项,但未能成功。
int numDups = 0,prevIndex = 0;
for (int i = 0; i < array.Length; i++)
{
bool foundDup = false;
for (int j = 0; j < i; j++)
{
if (array[i] == array[j])
{
foundDup = true;
numDups++; // Increment means Count for Duplicate found in array.
break;
}
}
if (foundDup == false)
{
array[prevIndex] = array[i];
prevIndex++;
}
}
// Just Duplicate records replce by zero.
for (int k = 1; k <= numDups; k++)
{
array[array.Length - k] = '\0';
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)