diff options
Diffstat (limited to '01-21.md')
-rw-r--r-- | 01-21.md | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -43,7 +43,7 @@ class bag{ - Our documentation indicates that **assignments and the copy constructor may be used with a bag** - Our plan is to use the **automatic assignment operator** and the **automatic copy constructor**, each of which simply copies the member variables from one bag to another - This is fine because **the copying process will copy both the data array and the member variable** `used` -- Ecample: If a programmer has two bags `x` and `y`, then the statement `y=x` will invoke the automatic assignment operator to copy all of `x.data` to `y.data`, and to copy `x.used` to `y.used` +- Example: If a programmer has two bags `x` and `y`, then the statement `y=x` will invoke the automatic assignment operator to copy all of `x.data` to `y.data`, and to copy `x.used` to `y.used` - Our only "work" for the value semantics is confirming that the automatic operations are correct ### Header File for the Bag Class @@ -115,7 +115,7 @@ bag::size_type bag::count(const value_type& target) const; ``` - We have used the completely specified type `bag::size_type` rather than just `size_type` - - Because many compiler do not recognize that you are implementing a bag member functino until after seeing `bag::count` + - Because many compiler do not recognize that you are implementing a bag member function until after seeing `bag::count` - In the implementation, after `bag::count`, we may use simpler names such as `size_type` and `value_type` - However, before `bag::count`, we should use the full type name `bag::size_type` @@ -183,7 +183,7 @@ void bag::operator +=(const bag& addend){ } ``` -- To avoid an explicit loop **we can used the copy functino from the <algorithm> Standard Library** +- To avoid an explicit loop **we can used the copy function from the <algorithm> Standard Library** ### An Object can be an Argument to its Own Member Function @@ -197,8 +197,8 @@ b.insert(2); b += b; ``` -- In the `+=` statement, the bag `b` is activating the `+=` operator, but this smae bag `b` is the actual argument to the operator -- This is a situatino that must be carefully tested +- In the `+=` statement, the bag `b` is activating the `+=` operator, but this same bag `b` is the actual argument to the operator +- This is a situation that must be carefully tested - **Example of the danger:** Consider the **incorrect** implementation of += ``` @@ -227,7 +227,7 @@ copy(<beginning location>, <ending location>, <destination>); ``` - It continues beyond the beginning location, copying more and more items to the next spot of the destination, until we are about to copy the ending location - **The ending location is not copied** -- This implementation uses the `copy` functino from the `<algorithm>` Standard Library +- This implementation uses the `copy` function from the `<algorithm>` Standard Library ``` void bag::operator +=(const bag& addend){ @@ -307,7 +307,7 @@ for(i = 0; i < used; ++i){ |Operation |Time Analysis | |-------------------|------------------------------------------------| -|Default constructor|O(1) (consant time) | +|Default constructor|O(1) (constant time) | |count |O(n) (n is the size of the bag) | |erase_one |O(n) (linear time) | |erase |O(n) (linear time) | |