CS 70

Phase 4

Now that IntList supports iteration, you get to actually use it in your own implementation code. In this development phase, you will implement the following member function(s) of the IntList class:

  • operator==(…) (the equal-to operator)

and as a result, this operator will also work:

  • operator!=(…) (the not equal-to operator, already written)

These operations are described in the

which you should keep open in a window or tab for reference.

Work Through the Steps

1. Plan

  • Plan how the == operator should work.
  • Add an image Phase_4.jpg to the intlist/Planning folder in your assignment repository.
  • Make sure the file was added successfully by viewing it on the GitHub website.

2. Write Tests

  • Write tests for == and != on IntLists and add them to intlist-test.cpp.

3. Implement

  • Use your plan to write your implementation of operator== in intlist.cpp.

4. Test & Fix

  • See if you can find any bugs in your implementation, and if you do, sort them out.
  • Think about how someone else might have accidentally fundamentally misunderstood what equality on lists means and make sure your test would catch those kinds of mistakes.

Helpful Hints

Use Your Iter

You should use your iterator to implement ==. Specificially, since both lists are const, when you call begin() on them, it'll return a const_iterator.

Note that you'll need to use two iterators, one for each list.

  • Dog speaking

    I know how to call begin on the RHS list, that's rhs.begin(), but how do I call it on the LHS list. I know that it's basically lhs.operator==(rhs), so is it this.begin() or this->begin()?

  • LHS Cow speaking

    You should just say begin() rather than this->begin(). (And this.begin() wouldn't compile, because this is a pointer.)

Obey the Complexity Guarantees

The specification lists specific complexity guarantees about the performance of == that limits your options on how you can implement this operation.

  • Rabbit speaking

    Yes, without those constraints, you'd have just been able to call std::equal passing in the begin() and end() iterators for both lists.

  • LHS Cow speaking

    We'll let you code == using std::equal in future assignments. But more practice is good right now.

To Complete This Part of the Assignment…

You'll know you're done with this part of the assignment when you've done all of the following:

(When logged in, completion status appears here.)