Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Enumerable Range
//C# 'Hello, world' //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { const int PivotValue = 1; const int RangeSize = 1; int[] enumerable = new[] { 0, 1, 2, 3, 4, 5, 600, 700, 800, 900, 1000 }; IEnumerable<int> range = enumerable.PivotRange(PivotValue, RangeSize); Console.WriteLine(String.Join(",",range.ToArray())); } } public static class EnumerableExtensions { public static IEnumerable<T> PivotRange<T>(this IEnumerable<T> source, T pivot, int size) where T : IComparable<T> { T[] left = new T[size]; int lCount = 0, rCount = 0; IEnumerator<T> enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { T item = enumerator.Current; if (item.CompareTo(pivot) == 0) { int start = lCount > size ? lCount % size : 0; int end = Math.Min(size, lCount); for (int i = start; i < start + end; i++) yield return left[i % size]; yield return pivot; while (enumerator.MoveNext() && rCount++ < size) yield return enumerator.Current; break; } if (size <= 0) continue; left[lCount++ % size] = item; } } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Intuit // C# // listing_4.4 (StreamReader // input.txt)
ckm9lgusa05fg0o0sez8h72ry8GTV
my first
Test equality
congtodien
filter distinct items from the array without builtin function - Seeni
ElaineBrown**
THRWSC SDXS
ANQ Bug with Feb month display
Hex_Base64
Please log in to post a comment.