[Tutor] Sorting a list manually

Dennis Lee Bieber wlfraed at ix.netcom.com
Thu Aug 12 13:17:19 EDT 2021


On Thu, 12 Aug 2021 21:49:34 +1200, dn via Tutor <tutor at python.org>
declaimed the following:

>
>Just tossing-around an idea:
>
>Another way to consider the bubble sort, would be to 'bubble' the
>smallest number to the 'left'/top (instead of the largest number to the
>right/bottom), then the next smallest, etc.
>

	I vaguely recall coding a double-ended bubble sort some 40+ years ago
-- it essentially moved the largest item in the active range to the end,
then reversed indexing to move the smallest item to the start; then reduced
the active range by one element at each end.

>So, using the min(), index(), and pop() or remove() list methods
>(functions), could one:
>- take the original_list as input, and create an empty destination_list
>- find the min() value and append() it to the destination_list
>- index() that value in the original_list and pop() it, or perhaps just
>remove() it (?speed comparison)
>- rinse and repeat (the latter two steps) until the original_list is
>"exhausted".
>

	<ouch> An "insertion sort" where all insertions are at the end of the
sorted-list? Granted, using the built-ins on the input list may be faster
than scanning the growing output list for the position, then splitting the
list to allow inserting the element at that place.



-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list