Created
November 17, 2020 21:54
-
-
Save JohnMGant/0ddebb95ddb5d4535502905007ab565f 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
| internal unsafe class PointerHeadTailAdder : IIntegerAdder | |
| { | |
| public int Add(int[] values) | |
| { | |
| fixed (int* head = values) | |
| { | |
| return AddImplementation(head, values.Length); | |
| } | |
| } | |
| private static int AddImplementation(int *head, int length) | |
| { | |
| if (length == 0) | |
| { | |
| return 0; | |
| } | |
| return *head + AddImplementation(++head, --length); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment