public new IEnumerable <T> Distinct() { var stackListQueue = new StackListQueue <T>(); if (Count == 0) { return(stackListQueue); } var arrays = new StackListQueue <StackListQueue <T> >(this); foreach (var arr in arrays.Where(arr => !IsSorted(arr))) { arr.Sort(Comparer); } List <int> indexes = arrays.Select((a, i) => 0).ToList(); List <int> counts = arrays.Select((a, i) => a.Count).ToList(); while (Enumerable.Range(0, 1).All(i => indexes[i] < counts[i] - 1)) { int value = Comparer.Compare(arrays[0][indexes[0]], arrays[0][indexes[0] + 1]); if (value == 0) { indexes[0]++; } else { stackListQueue.Add(arrays[0][indexes[0]++]); } } stackListQueue.Add(arrays[0][counts[0] - 1]); return(stackListQueue); }
public IEnumerable <T> Intersect(IEnumerable <T> array) { var stackListQueue = new StackListQueue <T>(); var arrays = new StackListQueue <StackListQueue <T> >(this) { new StackListQueue <T>(array) }; foreach (var arr in arrays.Where(arr => !IsSorted(arr))) { arr.Sort(Comparer); } List <int> indexes = arrays.Select((a, i) => 0).ToList(); List <int> counts = arrays.Select((a, i) => a.Count).ToList(); while (Enumerable.Range(0, 2).All(i => indexes[i] < counts[i])) { int value = Comparer.Compare(arrays[0][indexes[0]], arrays[1][indexes[1]]); if (value == 0) { stackListQueue.Add(arrays[0][indexes[0]++]); indexes[1]++; } else if (value < 0) { indexes[0]++; } else { indexes[1]++; } } return(stackListQueue); }