#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;
}

Edited 6 Years Ago by Nick Evan: Added code-tags

Fix what? A proper description of your problems will result in more useful replies.

Edited 6 Years Ago by Nick Evan: n/a

Fix what? A proper description of your problems will result in more useful replies.

the commented parts as in the fix me part

Edited 6 Years Ago by ndayala: n/a

the commented parts as in the fix me part

I see. So it isn't really a 'fix', but more a 'do my homework for me' :icon_wink:
You should read up on this.

Edited 6 Years Ago by Nick Evan: n/a

Comments
Yup, tutor boilerplate, for the student to fill in the missing blanks

>>[3, 3, 4, 3, 3, 3, 2, 8, 8]
// becomes...
// [3, 4, 3, 2, 8]

There is a handy function that does this in the stl, but I won't point you
to it. Notice that each adjacent elements are compared to, and if
the same then deleted. Try to emulate that.

I see. So it isn't really a 'fix', but more a 'do my homework for me' :icon_wink:
You should read up on this.

yes something like that

Comments
You really don't get it, do you?
This article has been dead for over six months. Start a new discussion instead.