Quick sort implementation in python
asnast at gmail.com
Fri Sep 26 19:17:42 CEST 2008
On Sep 25, 11:47 pm, "Martin v. Löwis" <mar... at v.loewis.de> 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 specific type of "a" matter
> for the algorithm. It could be a list, or it could be a different
> mutable collection that is integer-indexed.
> > My question is: Is that the normal way to implement algorithms in
> > python
> Yes, it is.
> > cause in c++ i've implemented that algo via a template function
> > which can have a randon access data structure or not. However i have
> > no idea how to access the values of a data structure that doesn't
> > allow random access.
> 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? Do can
swap 2 nodes of a linked list without random access (you can swap the
pointers or just swap the node values) and you traverse the list till
you reach it's tail.
More information about the Python-list