@define issorted(v){ @local i, m; m = length(v); if(islist(v)){ for(i = 1; i < m; i++) if(listref(v, i-1) > listref(v, i)) return 0; return 1; }else{ for(i = 1; i < m; i++) if(vecref(v, i-1) > vecref(v, i)) return 0; return 1; } } @define printit(v){ @local i, m; m = length(v); printf("{ "); if(islist(v)){ for(i = 0; i < m; i++) printf("%d ", listref(v, i)); }else{ for(i = 0; i < m; i++) printf("%d ", vecref(v, i)); } printf("}\n"); } @define cmp(x,y) { return x-y; } @define tst(v){ sort(v, cmp); printf("%d ", issorted(v)); printit(v); } tst([1,2,3]); tst([2,1]); tst([1,1]); tst([1,2]); tst([1]); tst([]); tst([3,2,1]); tst([3,1,3]); tst([3,3,1]); tst([1,3,3]); tst([1,4,2,6,2,7,1,4,2,6,8,4,0,-1,-4,-5,-9,3,-3,4]); tst(vector(1,2,3)); tst(vector(2,1)); tst(vector(1,1)); tst(vector(1,2)); tst(vector(1)); tst(vector()); tst(vector(3,2,1)); tst(vector(3,1,3)); tst(vector(3,3,1)); tst(vector(1,3,3)); tst(vector(1,4,2,6,2,7,1,4,2,6,8,4,0,-1,-4,-5,-9,3,-3,4));