Re: Quick sort implementation in python

2008-09-26 Thread Martin v. Löwis
>> Can you please explain how you did that in C? IOW, how did you do >> the partition function (template) in case you don't have random >> access to the collection? >> > > Why exactly do you need random access for partition function? This is a counter-question, not an answer. Let me ask again: Ho

Re: Quick sort implementation in python

2008-09-26 Thread sturlamolden
On 26 Sep, 08:43, Terry Reedy <[EMAIL PROTECTED]> wrote: > That depends on the data structure.  Access to a singly-linked list is > by linear scanning from the front. Which is one reason why mergesort i preferred over quicksort for lists. Pythons built-in sort is a variant of mergesort and should

Re: Quick sort implementation in python

2008-09-26 Thread Alex Snast
On Sep 25, 11:47 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > Now as you can see I'm passing my list object to both functions along > > with their first, last indices > > I cannot really see that. More specifically, it isn't definite what the > type of the "a" argument is, nor does the spec

Re: Quick sort implementation in python

2008-09-25 Thread Terry Reedy
Alex Snast wrote: Hi guys, I've been learning python in the past week and tried to implement a q.sort algorithm in python as follows: def quick_sort(l, first, last) if first < last: q = partition(a, first, last) You changed the name of the list to be sorted from 'l' to 'a'. Please

Re: Quick sort implementation in python

2008-09-25 Thread Martin v. Löwis
> Now as you can see I'm passing my list object to both functions along > with their first, last indices I cannot really see that. More specifically, it isn't definite what the type of the "a" argument is, nor does the specific type of "a" matter for the algorithm. It could be a list, or it could

Re: Quick sort implementation in python

2008-09-25 Thread bearophileHUGS
Alex Snast: > However i have no idea how to access the values of a data structure that > doesn't allow random access.< Well, a sorting algorithm can work in-place, sorting the position of the items inside the given collection, or it can create a new data structure with the items (in Python all it

Re: Quick sort implementation in python

2008-09-25 Thread Bruno Desthuilliers
Alex Snast a écrit : Hi guys, I've been learning python in the past week and tried to implement a q.sort algorithm in python Is that for learning purpose ? Else, it's just a waste of time... -- http://mail.python.org/mailman/listinfo/python-list