+ 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.

12th Oct 2018, 4:29 AM
Elias Dayoub
Elias Dayoub - avatar
3 Antworten
+ 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!
13th Oct 2018, 5:47 PM
Anton Böhler
Anton Böhler - avatar
+ 1
thanks Anton Böhler
25th Oct 2018, 6:16 PM
Elias Dayoub
Elias Dayoub - avatar
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
13th Oct 2018, 5:36 PM
Anton Böhler
Anton Böhler - avatar