title: bottom up mergesort
body: <p>i have following code for bottom up mergesort it does it's  operation on file   m-by-m merges  doubles m on each pass  here is code</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  inline int Min(int a,int b)
  {
      return a&lt;b?a:b;
  }
  
  void merge(int a[],int l,int m,int r)
  {
      vector&lt;int&gt;b;
      int i, j;
      for (i=m+1;i&gt;=l;i--)  b[i-1]=a[i-1];
      for (j=m;j&lt;r;j++) b[r+m-j]=a[j+1];
      for (int k=l;k&lt;=r;k++)
          if ( b[j]&lt;b[i]) 
              a[k]=b[j--];  
          else
              a[k]=b[i++];
  }
  
  void mergesort(int a[],int l,int r)
  {
      for (int m=1;m&lt;=r-l;m=m+m)
          for (int i=l;i&lt;=r-m;i+=m+m)
              merge(a,i,i+m-1,Min(i+m+m-1,r));
  }
  
  int main()
  {
      int a[]={12,4,7,3,9,8,10,11,6};
      int n=sizeof(a)/sizeof(int);
      mergesort(a,0,n-1);
      for (int i=0;i&lt;n;i++)
      {
          cout&lt;&lt;a[i]&lt;&lt; "  ";
      }
  
      return 0;
  }
  </code></pre>
  
  <p>but when i run this code   there is exception which says that vector's out of range error was occured please help </p>