#include <iostream>
#include <list>
using namespace std;
template <typename T>
class superlist : public list<T>
{
public:
// squish() is a mutator that "squish" together adjacent duplicate
// elements in a list.
//
// Example #1:
// [3, 3, 4, 3, 3, 3, 2, 8, 8]
// becomes...
// [3, 4, 3, 2, 8]
//
// Example #2:
// ["bob", "rick", "rick", "sally", "joe", "joe", "al", "joe"]
// becomes...
// ["bob", "rick", "sally", joe", "al", "joe"]
//
void squish()
{
// FIXME ... use iterators to traverse the list
}
// in_range() tells us whether 'value' falls in the range
// between the minimum value in the list and the maximum
// value in the list.
//
// Example:
// if the list is [3, 7, 4, 10, 5]
// the range of values in this list falls between 3 and 10
// therefore, in_range( 5 ) == true
// therefore, in_range( 12 ) == false
//
bool in_range( const T& value )
{
// FIXME ... use iterators to traverse the list
}
// print() displays the contents of the list to an output stream
// (separated by commas). A typical use of this member function
// would be:
// superlist<string> myList;
// myList.push_back( "one" );
// myList.push_back( "two" );
// myList.print( cout );
//
void print( ostream& out )
{
int n = this->size();
for ( typename superlist<T>::iterator iter = this->begin();
iter != this->end();
iter++
)
{
out << *iter;
n--;
if ( n != 0 )
out << ", ";
}
out << endl;
}
};
int main()
{
superlist<string> lst;
lst.push_back( "harry" );
lst.push_back( "harry" );
lst.push_back( "harry" );
lst.push_back( "jerry" );
lst.push_back( "jerry" );
lst.push_back( "larry" );
lst.push_back( "larry" );
lst.push_back( "larry" );
lst.print( cout );
lst.squish();
lst.print( cout );
superlist<int> ilst;
ilst.push_back( 3 );
ilst.push_back( 33 );
ilst.push_back( 23 );
ilst.push_back( 17 );
ilst.push_back( 12 );
ilst.print( cout );
cout << "Should be true: " << ilst.in_range( 20 ) << endl;
cout << "Should be true: " << ilst.in_range( 3 ) << endl;
cout << "Should be true: " << ilst.in_range( 33 ) << endl;
cout << "Should be false: " << ilst.in_range( 34 ) << endl;
return 0;
}
ndayala -2 Newbie Poster
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
ndayala -2 Newbie Poster
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
Salem commented: Yup, tutor boilerplate, for the student to fill in the missing blanks +19
mrnutty 761 Senior Poster
ndayala -2 Newbie Poster
Nick Evan commented: You really don't get it, do you? -2
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.