Run Code
|
API
|
Code Wall
|
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
list
linq jean by Fausto
Code
custom Generic Que Implementation
Bubble sort
linked list traversal
sdfghyjtgfredx
Classes
Prime no for specified max no by user(Using While Loop)
Brilliant.ArtificialNeuralNetworks.Perceptrons.PerceptronLeaningAlgori...