示例#1
0
文件: List.cpp 项目: laci37/hf
List<U> ListMapper<T,U>::map(List<T> l, U* (*f)(const T*)){
  ListElem<U> * sentinel= new ListElem<U>(NULL);
  ListElem<U> *last=sentinel;
  for(typename List<T>::iterator i=l.getIterator();!i.isAtEnd();i++){
    U* data=f(*i);
    ListElem<U> *act = new ListElem<U>(data);
    last->setNext(act);
    last=act;
  }
  return List<U>(sentinel);
}
示例#2
0
文件: List.cpp 项目: laci37/hf
List<U> ListMapper<T,U>::flatMap(List<T> l, List<U> (*f)(const T*)){
  ListElem<U> *s = new ListElem<U>(NULL);
  ListElem<U> *last=s;
  for(typename List<T>::iterator i=l.getIterator();!i.isAtEnd;i++){
    List<U> l2 = f(*i);
    for (typename List<U>::iterator j=l2.getIterator();!j.isAtEnd();j++){
      ListElem<U> *elem= new ListElem<U>(new U(**j));
      last->setNext(elem);
      last=elem;
    }
  }
  return List<U>(s);
}