























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























template< class T > class Vector { private: T* ptr; int size; public: Vector( int = 10 ); Vector( const Vector< T >& ); ~Vector(); int getSize() const;
const Vector< T >& operator =( const Vector< T >& ); T& operator ; T* first(); T* beyond(); T* next( T* );
};
template< class T >
T* Vector< T >::next( T* current )
{
if ( current < (ptr + size) ) return ( current + 1 ); // else return current;
}
int main() {
Vector< int > iv( 3 ); iv[0] = 10; iv[1] = 20; iv[2] = 30; int* first = iv.first(); int* beyond = iv.beyond(); int* found = find(first,beyond,20); return 0;
}
a b c d e f g …
Cursor
int main() {
Set< int > is( 3 ); is.add( 10 ); is.add( 20 ); is.add( 30 ); ET* first = iv.first(); ET* beyond = iv.beyond(); ET* found = find(first, beyond, 20); return 0;
}
template< typename P, typename T > P find( P start, P beyond, const T& x ) { while ( start != beyond && *start != x ) ++start; // Error
return start; }
int main() {
Set< int > is( 3 ); is.add( 10 ); is.add( 20 ); is.add( 30 ); int* found = find( is, 20 ); return 0;
}
a b c d e f g …
Cursor 1 Cursor 2