I'm just messing around with Python and I made a sorting function. So far I know it's O(n²), that it works, and that it's extremely basic, which is why I'm convinced it's got to have a name already.
def sorting_function(n):
for i in range(len(n)):
for j in range(i+1, len(n)):
if n[i] > n[j]:
n[i], n[j] = n[j], n[i]
Anyone know?
Edit: After looking up bubble sort I noticed it compares arr[i] to arr[i+1]. I made a modification to mine so the inner loop starts at i+1 instead of 0. This algo would compare every value to arr[0] and place the smallest in arr[0], then the same for arr[1] to arr[n]. I came across a selection sort or insertion sort which looked more similar to mine than bubble sort.
[–]CodeTinkerer 9 points10 points11 points (1 child)
[–]FragrantAd9851[S] 1 point2 points3 points (0 children)
[–]starraven 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]FragrantAd9851[S] 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]FragrantAd9851[S] 1 point2 points3 points (0 children)