-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymmetricDifference.cs
60 lines (52 loc) · 1.58 KB
/
SymmetricDifference.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Collections.Generic;
using System.Linq;
namespace SymmetricDifferenceAlgorithm
{
internal class SymmetricDifference
{
private int[][] _SETS;
private List<int> _SYMMETRIC_DIFFERENCE;
public SymmetricDifference(int[][] sets)
{
this._SETS = sets;
this._SYMMETRIC_DIFFERENCE = _SETS[0].ToList();
}
public List<int> Calculate()
{
for (int i = 1; i < _SETS.Length; i++)
{
_SYMMETRIC_DIFFERENCE = Difference(_SYMMETRIC_DIFFERENCE, _SETS[i]);
}
return _SYMMETRIC_DIFFERENCE;
}
private bool IsUnique(int control, List<int> symmetric_difference)
{
if (symmetric_difference.Contains(control))
{
return false;
}
else
{
return true;
}
}
private List<int> Difference(List<int> set1, int[] set2)
{
List<int> symmetric_difference = set1.AsQueryable().Distinct().ToList();
List<int> group = set2.ToList().AsQueryable().Distinct().ToList();
for (int i = 0; i < group.Count; i++)
{
if (IsUnique(group[i], symmetric_difference))
{
symmetric_difference.Add(group[i]);
}
else
{
symmetric_difference.Remove(group[i]);
}
}
symmetric_difference.Sort();
return symmetric_difference;
}
}
}