Last active
September 14, 2019 04:27
-
-
Save imgen/62c4117784691c79b11b680d170d9b13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public IEnumerable<T> ConcatTwoOrderedArray<T>(IReadOnlyList<T> first, IReadOnlyList<T> second) | |
| { | |
| dynamic dynamicFirst = first, dynamicSecond = second; | |
| for (int i = 0, j = 0; i < first.Count || j < second.Count;) | |
| { | |
| if (i < first.Count && (j >= second.Count || dynamicFirst[i] < dynamicSecond[j])) | |
| yield return first[i++]; | |
| else | |
| yield return second[j++]; | |
| } | |
| } | |
| public IEnumerable<T> ConcatTwoOrderedArray<T>(IEnumerable<T> first, IEnumerable<T> second) | |
| { | |
| using(IEnumerator<T> firstWalker = first.GetEnumerator(), secondWalker = second.GetEnumerator()) | |
| { | |
| var firstCanMoveNext = firstWalker.MoveNext(); | |
| var secondCanMoveNext = secondWalker.MoveNext(); | |
| while(firstCanMoveNext || secondCanMoveNext) | |
| { | |
| if (firstCanMoveNext && (!secondCanMoveNext || (dynamic)firstWalker.Current < secondWalker.Current)) | |
| { | |
| yield return firstWalker.Current; | |
| firstCanMoveNext = firstWalker.MoveNext(); | |
| } | |
| else | |
| { | |
| yield return secondWalker.Current; | |
| secondCanMoveNext = secondWalker.MoveNext(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment