+ 4

Sorting Working Python

I have tried making sorting the number list, https://code.sololearn.com/cMKtKArcBenY/ and I dont know, what algorithm is it called because I coded it thinking its algorithm myself. But it doesnt sort the numbers well. It works up to some extent, i.e 30% Any suggestion how to solve it?

22nd Mar 2020, 3:28 PM
Sarthak
Sarthak - avatar
12 odpowiedzi
+ 1
On line 25, replace sort_prev_repeat(sorted_array) with sorted_array = sort_prev_repeat(sorted_array) The algorithm you have implemented here is called "insertion sort", by the way.
23rd Mar 2020, 1:35 AM
Schindlabua
Schindlabua - avatar
+ 5
maf I don't know. I created my own
22nd Mar 2020, 4:08 PM
Sarthak
Sarthak - avatar
22nd Mar 2020, 4:20 PM
Alfred Juma
Alfred Juma - avatar
+ 2
Sarthak 🇳🇵 according to which algorithm are you trying to sort the list?
22nd Mar 2020, 4:07 PM
maf
maf - avatar
+ 2
Sarthak 🇳🇵 lol. If u explain me like what is ur desired output, then I would be probavly be able to solve the problem.
22nd Mar 2020, 4:09 PM
maf
maf - avatar
+ 2
Alfred Juma No, I wanted to sort using my own sorting algorithm. maf Sorry, for for less-clarification of code. I'll try to provide you clarification tomorrow in a paper, and here it's time to sleep now.
22nd Mar 2020, 4:31 PM
Sarthak
Sarthak - avatar
23rd Mar 2020, 10:27 AM
Sarthak
Sarthak - avatar
+ 2
John Robotane I know that. I was just trying to understand the algorithm that my brain uses to sort array. And just tried to implement that algorithm in python.
24th Mar 2020, 11:04 AM
Sarthak
Sarthak - avatar
+ 1
Why not use the built in sort() or sorted()
22nd Mar 2020, 4:51 PM
Justus
Justus - avatar
+ 1
as Justus said it, it's better to use the built in fonctions, they are more optimized and avoid you headaches!
24th Mar 2020, 10:59 AM
John Robotane
John Robotane - avatar
+ 1
alright, there is a Sololearn course about sorting: https://www.sololearn.com/learn/774/?ref=app
24th Mar 2020, 11:58 AM
John Robotane
John Robotane - avatar
0
Sarthak 🇳🇵 alright no prob
22nd Mar 2020, 4:31 PM
maf
maf - avatar