Move element forward in list (SML) -


is possible move element in list forward in sml, let's 2 steps, 3 in [1,2,3,4,5,6] ends [1,2,4,5,3,6]?

basically, need define helpful function returns exact position of element want change. in have this, assuming have 1 3 in list. if want move 3s forward, make curr (position) list:

exception doesntexit  fun look3 (li, curr) = if (hd(li) == 3) curr else look3 (tl(li), curr + 1)   | look3 (nil, curr) = raise doesntexit     

now have exact position curr of 3 want move forward, need use combination of list.take() , list.drop() trivial have desired output.

this method not limited element want change, neither list length, nor list type.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -