zoukankan      html  css  js  c++  java
  • list相关的习题

    代码如下

     1 -module(adv_list).
     2 -export([filter/2, reverse/1, concatenate/1, flatten/1]).
     3 
     4 filter(List, Value) ->
     5     FiltedList = [X || X<-List, X=<Value],
     6     io:format("filted:~w~n", [FiltedList]).
     7 
     8 reverse(List) ->
     9     RevertedList = revert(List, []),
    10     io:format("reverted:~w~n", [RevertedList]),
    11     RevertedList.
    12 
    13 revert([H|T], RevertedList) ->
    14     revert(T, [H] ++ RevertedList);
    15 revert([], RevertedList) ->
    16     RevertedList.
    17 
    18 concatenate(List) ->
    19     ConcatedList = concate(List, []),
    20     io:format("concated:~w~n", [ConcatedList]).
    21 
    22 concate([H|T], ConcatedList) ->
    23     concate(T, reverse(H) ++ ConcatedList);
    24 concate([], ConcatedList) ->
    25     reverse(ConcatedList).
    26 
    27 flatten(List) ->
    28     FlatedList = reverse(flat(List, [])),
    29     io:format("flated:~w~n", [FlatedList]).
    30 
    31 flat([H|T], FlatedList) ->
    32     case is_list(H) of
    33         true -> flat(T, flat(H, FlatedList));
    34         false -> flat(T, [H] ++ FlatedList)
    35     end;
    36 flat([], FlatedList) ->
    37     FlatedList.
    上善若水
  • 相关阅读:
    Java线程面试题 Top 50
    深入理解java内存模型
    线程池的理解
    Thread的理解
    ThreadLocal的理解
    排序算法(简)
    排序算法
    【Java集合源码剖析】LinkedHashmap源码剖析
    vsftp上传文件权限问题
    xp 通过注册表修改环境变量
  • 原文地址:https://www.cnblogs.com/netbuddy/p/2823635.html
Copyright © 2011-2022 走看看