title: Resize method intArray
body: <p>I'm writting an <code>IntArray</code> class for college but don't know how to write my <code>resize</code> method efficiently. What I have doesn't support resizing to smaller lists and I don't know how to fix that..</p>
  
  <p>Here is my code:</p>
  
  <pre><code> void IntArray::resize(unsigned int size){
       for (int i = size;i&lt;length;i++){
           data[i] = 0;
       }
       length = size;
   }
  </code></pre>
  
  <p>header file</p>
  
  <pre><code>#ifndef INTARRAY_H_
  #define INTARRAY_H_
  
  #include &lt;iostream&gt;
  using namespace std;
  
  class IntArray{
  private:
       int length;
       int * data;
  public:
      IntArray(int size = 0);
      IntArray(const IntArray&amp; other);
      IntArray&amp; operator=(const IntArray&amp; original);
  
      int getSize() const { return length; };
      int&amp; operator[](unsigned int i);
      void resize(unsigned int size);
      void insertBefore(int value, int index);
  
      friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const IntArray&amp; list);
      ~IntArray(){ delete[] data; };
  };
  </code></pre>