#include <numeric.h> int main() { array double x1[4] = {0.1, NaN, -0.1, 3}, y1[4]; array double complex x2[2][3] = {5, NaN, -3, -6, 3, 5}, y2[2][3]; array int inde1[2][3]; array double x4[3][3] = {1, 3, -3, -2, 3, 5, 9, 2, 4}, y4[3][3]; array int inde[3][3]; array double x3[2][3][4],y3[2][3][4]; x3[1][1][2] = 10; x3[1][2][2] = -10; sort(y1, x1); // sort by total elements printf("sort by total elements\n"); printf("x1 = %5.2f\n", x1); printf("sort(x1) = %5.2f\n", y1); sort(y2, x2, "row", inde1); printf("sort by row, gives index array\n"); printf("x2 = %f\n", x2); printf("sort(x2)\n"); printf("%f\n", y2); printf("index(x2)\n"); printf("%d\n", inde1); sort(y3, x3, "array"); printf("sort by total elements \n"); printf("x3 = %f\n", x3); printf("sort(x3)\n"); printf("%f\n", y3); sort(y4, x4, "column", inde); printf("sort by column elements, gives index array\n"); printf("x4 = %f\n", x4); printf("sort(x4)\n"); printf("%f\n", y4); printf("inde(x4)\n"); printf("%d\n", inde); }
sort by total elements x1 = 0.10 NaN -0.10 3.00 sort(x1) = -0.10 0.10 3.00 NaN sort by row, gives index array x2 = complex(5.000000,0.000000) ComplexNaN complex(-3.000000,0.000000) complex(-6.000000,0.000000) complex(3.000000,0.000000) complex(5.000000,0.000000) sort(x2) complex(-3.000000,0.000000) complex(5.000000,0.000000) ComplexNaN complex(3.000000,0.000000) complex(5.000000,0.000000) complex(-6.000000,0.000000) index(x2) 3 1 2 2 3 1 sort by total elements x3 = 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 10.000000 0.000000 0.000000 0.000000 -10.000000 0.000000 sort(x3) -10.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 10.000000 sort by column elements, gives index array x4 = 1.000000 3.000000 -3.000000 -2.000000 3.000000 5.000000 9.000000 2.000000 4.000000 sort(x4) -2.000000 2.000000 -3.000000 1.000000 3.000000 4.000000 9.000000 3.000000 5.000000 inde(x4) 2 3 1 1 1 3 3 2 2