bool TestAlgorithms( ) { bool ok = true; cout << "Testing Algorithms" << endl; int numbers[4] = { 0, 1, 2, 3 }; string numberNames[4] = { "zero", "one", "two", "three" }; TESTCHECK( *(MinIter( numbers, numbers + 4 )), 0, &ok ); TESTCHECK( *(MaxIter( numbers, numbers + 4 )), 3, &ok ); TESTCHECK( *(MinIter( numberNames, numberNames + 4 )), string( "one" ), &ok ); TESTCHECK( *(MaxIter( numberNames, numberNames + 4 )), string( "zero" ), &ok ); TESTCHECK( *(MaxIter( numberNames + 1, numberNames + 4 )), string( "two" ), &ok ); TESTCHECK( MinIndex( numbers, numbers + 4 ), 0, &ok ); TESTCHECK( MaxIndex( numbers, numbers + 4 ), 3, &ok ); TESTCHECK( MinIndex( numberNames, numberNames + 4 ), 1, &ok ); TESTCHECK( MaxIndex( numberNames, numberNames + 4 ), 0, &ok ); TESTCHECK( MaxIndex( numberNames + 1, numberNames + 4 ), 1, &ok ); if ( ok ) cout << "Algorithms PASSED." << endl << endl; else cout << "Algorithms FAILED." << endl << endl; return ok; }
int main(void) { int anArr[7] = {1, 2, 3, 4, 5, 8, 10}; printf("The index of the largest one is %d", MaxIndex(&anArr, SIZE)); return 0; }
VectorSpace<Type, N> VectorSpace<Type, N>::operator - (const Type& offset) const { // Vectors should have same size VectorSpace<Type, N> result; for (int i= MinIndex(); i <= MaxIndex(); ++i) { result[i] = (*this)[i] - offset; } return result; }
VectorSpace<Type, N> VectorSpace<Type, N>::operator - () const { // The negation of a vector // Vectors should have same size VectorSpace<Type, N> result; for (int i= MinIndex(); i <= MaxIndex(); ++i) { result[i] = -(*this)[i]; } return result; }
int CODMenuDataArray::Append( const CODMenuDataArray &other ) { int nResult = MaxIndex(); for ( int i=0,c=other.Count(); i<c; i++ ) Add( other[i] ); return nResult; }
template <class type> const type& Vector<type>::MaxValue() const { return Data[MaxIndex()]; }
TBtInnerNode::TBtInnerNode() { new TBtItem[MaxIndex()+1]; }