0

So I have this function I need to create which in addition to a binary search must do some data mining (so not a pure binary search)/

CustomBinarySearch(int goal, int[] myArray)

I know quite clearly how to go about making a binary search. The problem stems from the signature of the function. I would normally pass the index values of the sub-array as I recursively call it but I am required to maintain the original signature.

Is there any way to pass a sub-segment of an array without creating a new array? I am trying to be efficient with my code.

aka something like CustomBinarySearch(goal, myArray[startIndex, endIndex])?

1
  • You may want to read up on ArraySegment<T> Commented Mar 7, 2016 at 23:59

1 Answer 1

2

The problem stems from the signature of the function. I would normally pass the index values of the sub-array as I recursively call it but I am required to maintain the original signature.

Make your public method call a private method that has the signature you prefer.

Is there any way to pass a sub-segment of an array without creating a new array?

This feature is proposed for C# 7.

Sign up to request clarification or add additional context in comments.

1 Comment

I have thought about the private method but I am not sure if I would be allowed to do that hence the post. I will look into it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.