正在加载图片...
From pointers to iterators(cont,) a better implementation adding a sentinel pointer that pointing to the next address of the last element, which could replace the size parameter using pointer dereference to replace subscription template <typename ElemType> ElemType* find(const Elem Type* first, const ElemType* last, const ElemType &value) if((! first)II(! last)) return O; for (i first != last; first++) if first = Value) return first } return OF }From pointers to iterators (cont.) ◼ A better implementation: ◼ adding a sentinel pointer that pointing to the next address of the last element, which could replace the size parameter ◼ using pointer dereference to replace subscription template <typename ElemType> ElemType* find(const ElemType* first , const ElemType* last , const ElemType &Value) { if ((! first) || (! last)) return 0; for (; first != last; first++) { if (*first == Value) return first; } return 0; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有