0

Why the loop never ends ? How to fix it ?

This is implementation of merge sort and this is my own method , I know that it is often implemented by using recrusion . The problem is that it shows no output , that means the while loop never terminates . Please show me how can I fix it ... https://pastebin.ubuntu.com/p/WCXKPy494B

22nd Jun 2021, 2:21 PM
Ali_combination
Ali_combination - avatar
14 Antworten
+ 3
I don't rate codes... I try to debug them... I know that you're coding for competitive challenge, but I haven't looked your code in details and I'm not really aware of sorting algorithms: my rate would have really few interest ;P
22nd Jun 2021, 3:02 PM
visph
visph - avatar
+ 2
copy your code in sololearn playground, and paste the link to it... that would be more easy to help you ^^
22nd Jun 2021, 2:23 PM
visph
visph - avatar
0
visph https://code.sololearn.com/c12a5A0a22A1/?ref=app Here you are Visph ... I haven't used recrusion this time =) and you may find it too complex ... please just consider the merge sort part , other parts work properly .
22nd Jun 2021, 2:30 PM
Ali_combination
Ali_combination - avatar
0
what is the use of second argument of merge_sort function? I didn't see where it is used? anyway, your code produce no output because you don't call any of the defined functions... and there's no global script to run ^^ calling merge_sort with an array and any value, such as: print(merge_sort([5,3,8,1],'foobar')) seems to always return (and print) an empty array ;P
22nd Jun 2021, 2:46 PM
visph
visph - avatar
0
visph Ummm I just pasted the functions , you can use the merge sort like the way you just mentioned . It will show no output.. see the code again . It only outputs [] .. i dont understand which part deletes elements of the list ..
22nd Jun 2021, 2:50 PM
Ali_combination
Ali_combination - avatar
0
only outputing empty list is different to showing no output...
22nd Jun 2021, 2:53 PM
visph
visph - avatar
0
visph im still trying to fix it . This code is not my initial code ... the initial one does not even show the empty list . I edited that , and this one shows only an empty list
22nd Jun 2021, 2:54 PM
Ali_combination
Ali_combination - avatar
0
your two calls to clear() method delete the content newly appended... remove these two lines and your merge sort works fine ;)
22nd Jun 2021, 2:55 PM
visph
visph - avatar
0
lines 46 and 35
22nd Jun 2021, 2:56 PM
visph
visph - avatar
0
visph thank you so much gentleman ;) And a quick question , how do you rate my code ? As I did not use recrusion ... does it almost have the same quality(considering time complexity) as other usual ones have ? (those which use recrusion)
22nd Jun 2021, 2:59 PM
Ali_combination
Ali_combination - avatar
0
visph okay ... thanks .
22nd Jun 2021, 3:05 PM
Ali_combination
Ali_combination - avatar
0
Loop is a example like a : put the water bucket while it is not full Like that we written a range and it stop of end of the last digit of the range
24th Jun 2021, 6:50 AM
Girish Unde
24th Jun 2021, 6:53 AM
Girish Unde
0
For stopping a loop you can use break function and enter the value on which you want to stop the loop.
24th Jun 2021, 12:04 PM
Minotic
Minotic - avatar