The c ++ Programming Language Lecture 3: Standard Template Library Generic Programming
The C++ Programming Language Lecture 3: Standard Template Library & Generic Programming
Brief introduction
Brief Introduction
Generic Programming Core idea Data structures and data types should be independent Data structures and algorithms should be independent Algorithms and data types should be independent (generic STL supports GP well Including 2 parts Container: vector, list, map, set..(basic data structures Generic Algorithm: find, sort, merge..(frequently used operations
Generic Programming ◼ Core idea ◼ Data structures and data types should be independent ◼ Data structures and algorithms should be independent ◼ Algorithms and data types should be independent (generic) ◼ STL supports GP well ◼ Including 2 parts ◼ Container: vector, list, map, set,… (basic data structures) ◼ Generic Algorithm: find, sort, merge,… (frequently used operations)
Generic Programming(cont u Container supported the independence between data types and data structures list<int>, list<double> Iterators supported the independence between data structures and algorithms sort(vec, begin, vec. endO; Function templates supported the independence between algorithms and data types template <typename elemType binary_search(const vector< ElemType>&, ElemType&)
Generic Programming (cont.) ◼ Container supported the independence between data types and data structures ◼ list<int>, list<double> ◼ Iterators supported the independence between data structures and algorithms ◼ sort(vec.begin(), vec.end()); ◼ Function templates supported the independence between algorithms and data types ◼ template <typename ElemType> binary_search(const vector<ElemType>&, ElemType&);
From Pointers to iterators
From Pointers to Iterators