Hi.
I would like to implement a sorting algorithm in one line of code if
possible.
n=[7,4,9,55,98,11,42]
n.inject(n[0]) {|min, i| min=i if i<min; min}
I first find lowest number in list and then would like to replace it
with
first element. After that I need to start from the second element, find
the
lowest element, replace it with that second element and so on till I
reach
the end of a list.
I don’t know how this sorting algorithm is called ?
I managed to find the minimum in the above code. What next ? How to
replace
two elements ?
The result is a number object. Where do I (in general) put a dot in
above
expression to perform some methods on that object (when expression has a
block {} of code in itself ) ?
Can you also show me that for a quick sort ?
Thanks
Haris