Elad
Member
- Joined
- Feb 15, 2020
- Messages
- 20
- Programming Experience
- 1-3
hello!
I want to build a Merge Sort sort, but I ran into a pretty annoying problem. In C++ or even in C I send an array or pointer to a function the pointer is always pointing to the first member so it is very easy to send to the recursive function the array every time in some member and not necessarily in the first member of the original array, or in other words you can promote a pointer. In C# life is supposed to be simple but I see no way to send the array to a function so that the array starts from a particular member so I can not promote the "Pointer" (in c # I know that Pointers are something different from the Pointers in c ++ or C) of The array.
If I can still send the array to a function and recursively can I somehow make a kind of promotion to the array?
I know there are examples of merge sort in c # but all the examples I saw are very cumbersome compared to the code in C++
The following is an example ():
I want to build a Merge Sort sort, but I ran into a pretty annoying problem. In C++ or even in C I send an array or pointer to a function the pointer is always pointing to the first member so it is very easy to send to the recursive function the array every time in some member and not necessarily in the first member of the original array, or in other words you can promote a pointer. In C# life is supposed to be simple but I see no way to send the array to a function so that the array starts from a particular member so I can not promote the "Pointer" (in c # I know that Pointers are something different from the Pointers in c ++ or C) of The array.
If I can still send the array to a function and recursively can I somehow make a kind of promotion to the array?
I know there are examples of merge sort in c # but all the examples I saw are very cumbersome compared to the code in C++
The following is an example ():
C#:
static void mergeSort(int[] arr, int p,int [] helper)
{
int left = p / 2;
int right = p - left;
if (p < 2)
{
return;
}
//In c # it does not work that way:
mergeSort(arr + left, p, helper);
//...Missing continuation of the code
}
Last edited by a moderator: