Homework/HW01/MyArray.cc
void MyArray::resize(int theSize)
{
    if (theSize >= 0) // check that the new size is valid
    {
        if (size > 0) // if the array is not empty, deallocate first
            empty();
        if (theSize != 0) // allocate again if the size is not 0
        {
            size = theSize;
            array = new int[size];
        }
    }
    else // negative size, give an error message
        cout << "Resize attepmted with a negative size. "
             << "Operation ignored." << endl;
}
// Resize the array with the new size. If the object contains an
// array, it is deallocated first.
Resize the array with the new size. If the object contains an
array, it is deallocated first.
Resize the array with the new size . If the object contains an array it is deallocated first .
void MyArray::resize(int theSize)
{
    if (theSize >= 0) 
    {
        if (size > 0) 
            empty();
        if (theSize != 0) 
        {
            size = theSize;
            array = new int[size];
        }
    }
    else 
        cout << "Resize attepmted with a negative size. "
             << "Operation ignored." << endl;
}
void MyArray :: resize ( int theSize ) { if ( theSize >= 0 ) { if ( size > 0 ) empty ( ) ; if ( theSize != 0 ) { size = theSize ; array = new int [ size ] ; } } else cout << " " << " " << endl ; }
Resize the array with the new size.
Resize the array with the new size .
// check that the new size is valid // if the array is not empty, deallocate first // allocate again if the size is not 0 // negative size, give an error message