+ 1
I wanna help in a sort function
please. I read about sort by merge sort ..I understanded the algorithm but It's diffecult to write it in a code . I found the code yoo complicated .. so , I wish you help me to write simple code. or at the least to understand how the compiler work.
3 Réponses
+ 1
the first part of the function "mergeSort()" gets the inputed array and makes every element have it's own array.
The next part checks if there is an uneven amount of elements and then merges every second element with it's partner. If it was uneven the last element is merged at the end.
the last step is repeated until the elements are all in one array/list
the function "merge()" takes two arrays/lists and using the integers "i" and "j" it's checked weather the current element of the first array is bigger than the other. Then it gets added to the result and the index that pointed at it ("i"/"j") is increased.
repeated until on array is gone throw complitly.
late the rest-elements of the other array are add.
then the array is returned as one.
ok it sound complicated, but that makes it more fun! good luck!
+ 1
thanks Anton Böhler
0
https://code.sololearn.com/cTPMvaR1ALgR/?ref=app
I know this is python but maybe helps ...
It looks complicated but it's not that hard