boe wrote on Sep 15th, 2015, 4:27am:b=sort(copy(a), 'lessp)
(-5 0 1 6 7
7 8 9 9 11
11 11 12
)
Thanks for replying.
If I want to remove duplicate elements, how can I do it ?
I created my own awkward custom function like following.
I can do my favorite task with this custom function, but not cool.
Code:procedure( list_sort(l_list,
@optional (my_mode 0), (rm_duplicate 0)
); list_sort
prog( (i, k, ii, jj, n, p, my_value)
n = length(l_list)
declare(p[n])
for(i, 0, n-1
p[i] = nth(i, l_list)
); for
for(ii, 0, n-2
my_value = p[ii]
k = ii
for(jj, ii+1, n-1
prog( ()
if(my_mode == 0 then
when( my_value < p[jj], return() ) ; ascend
else
when( my_value > p[jj], return() ) ; descend
); if
my_value = p[jj]
k = jj
); prog
); for
p[k] = p[ii]
p[ii] = my_value
); for
my_value = p[0]
l_list = list(my_value)
for(i, 1, n-1
if(rm_duplicate != 0 then
when(p[i] != my_value
my_value = p[i]
l_list = append1(l_list, my_value)
); when
else
l_list = append1(l_list, p[i])
); if
); for
return(l_list)
); prog
); procedure
\i list_sort('(2 11 11 11 10 10 9 9 4 0 -1), 0)
\t (-1 0 2 4 9
\t 9 10 10 11 11
\t 11
\t )
\p >
\i list_sort('(2 11 11 11 10 10 9 9 4 0 -1), 0, 1)
\t (-1 0 2 4 9
\t 10 11
\t )
\p >
\i list_sort('(2 11 11 11 10 10 9 9 4 0 -1), 1)
\t (11 11 11 10 10
\t 9 9 4 2 0
\t -1
\t )
\p >
\i list_sort('(2 11 11 11 10 10 9 9 4 0 -1), 1, 1)
\t (11 10 9 4 2
\t 0 -1
\t )
I can do same tasks very easily with MATLAB.