Sorts an array or a set of arrays.

void sort(int number, array1[, array2,...]);

The sort function either directly sorts a given array1, or it sorts a set of arrays (starting with array2), in which case array1 is supposed to be an array of int, which will be used as a pointer array.

In any case, the number argument defines the number of items in the array(s).

Sorting a single array

If the sort function is called with one single array, that array will be sorted directly, as in the following example:

string A[];
int n = 0;
A[n++] = "World";
A[n++] = "Hello";
A[n++] = "The truth is out there...";
sort(n, a);
for (int i = 0; i < n; ++i)
Sorting a set of arrays

If the sort function is called with more than one array, the first array must be an array of int, while all of the other arrays may be of any array type and hold the data to be sorted. The following example illustrates how the first array will be used as a pointer:

numeric string Nets[], Parts[], Instances[], Pins[];
int n = 0;
int index[];
schematic(S) {
  S.nets(N) N.pinrefs(P) {
    Nets[n] = N.name;
    Parts[n] = P.part.name;
    Instances[n] = P.instance.name;
    Pins[n] = P.pin.name;
  sort(n, index, Nets, Parts, Instances, Pins);
  for (int i = 0; i < n; ++i)
      printf("%-8s %-8s %-8s %-8s\n",
             Nets[index[i]], Parts[index[i]],
             Instances[index[i]], Pins[index[i]]);
The idea behind this is that one net can have several pins connected to it, and in a netlist you might want to have the net names sorted, and within one net you also want the part names sorted and so on.

Note the use of the keyword numeric in the string arrays. This causes the strings to be sorted in a way that takes into account a numeric part at the end of the strings, which leads to IC1, IC2,... IC9, IC10 instead of the alphabetical order IC1, IC10, IC2,...IC9.

When sorting a set of arrays, the first (index) array must be of type int and need not be initialized. Any contents the index array might have before calling the sort function will be overwritten by the resulting index values.

Index Copyright © 2005 CadSoft Computer GmbH