Re: Ordenacion de arrays.
Posted in 1998
On Tue, 13 Oct 1998, Juan Manuel Hernandez del Olmo wrote: > Ordenacion de arrays. > Necesitaria una funcion para ordenar los elementos de un array en 4GL. My Spanish isn't all that good (it's more like non-existent), but I'm guessing you are asking for a function to sort the elements of an array in I4GL. It isn't particularly easy to do; it is virtually impossible to write a generic routine to sort the data. Because you can't pass arrays around, they have to be module or global variables. You can find all sorts of sorting algorithms in books; which one is sensible depends on how big the arrays are (number of elements), the size of each element, the complexity of the comparison, and on whether the sort needs to be stable or not. When designing the comparison, don't forget to handle nulls sensibly. If you are dealing with a few tens of elements and the arrays are of integers, then it is all pretty simple and even a bubble sort will do. If you are dealing with thousands of elements and each element is a 2 kB record and the sort criterion has 6 fields to be compared, then it is rather important to keep both the number of moves and the number of comparisons down -- and a bubble sort is probably not appropriate. > MUCHAS GRACIAS. Try: "Programming Pearls" and "More Programming Pearls" by Jon Bentley, or consider Knuth Volume 3 "Sorting and Searching", or Sedgewick's "Algorithms in X" (pick your language other than I4GL) books. Or any half-way decent algorithms book; even K&R "The C Programming Language" contains a shell sort which is reasonable for many applications. Yours, Jonathan Leffler (jleffler@informix.com) #include <witticism.h> Guardian of DBD::Informix v0.60 -- http://www.perl.com/CPAN Informix IDN for D4GL & Linux -- http://www.informix.com/idn