title: Print Max Subarray Values From An Array After Running Divide And Conquer Algorithm
body: <p>I have implemented a solution to find the maximum subarray from an array of values. I can print out the full array prior to running my divide and conquer algorithm, but I cannot seem to figure out how to print the subarray after the algorithm is run.</p>
  
  <pre><code>int newArray[] = {31, -41, 59, 26, -53, 58, 97, -93, -23, 84};
  
  int arraySize = (sizeof(newArray)/sizeof(int));
  
  printArray(newArray, 0, arraySize - 1);
  
  int total = maxSubDiv(newArray, 0, arraySize - 1);
  </code></pre>
  
  <p>This is a snippet of my main function. I am using a printArray function to print the full array prior to finding the maximum subarray. The maxSubDiv function is as follows:</p>
  
  <pre><code>int maxSubDiv(int * Array1, int left, int right)
  {
      if(left == right)
      {
          return Array1[1];
      }
  
      int middle = (left + right)/2;
  
      return findMax(maxSubDiv(Array1, left, middle), maxSubDiv(Array1, middle + 1, right), leftRightCross(Array1, left, middle, right));
  
  }
  
  int leftRightCross(int * Array1, int left, int middle, int right)
  {
      int sum = 0;
  
      int leftSum = INT_MIN;
  
      for(int i = middle; i &gt;= left; i--)
      {
          sum = sum + Array1[i];
          if(sum &gt; leftSum)
          {
              leftSum = sum;
          }
      }
  
      sum = 0;
      int rightSum = INT_MIN;
  
      for(int i = middle + 1; i &lt;= right; i++)
      {
          sum = sum + Array1[i];
          if(sum &gt; rightSum)
          {
              rightSum = sum;
          }
      }
  
      sum = leftSum + rightSum;
  
      return sum;
  }
  </code></pre>
  
  <p>The algorithm seems to test well, but I am just having trouble printing out the subarray that contains the integers of the max subarray. Any help is much appreciated!</p>
  
  <pre><code>struct tuple{
  
      int begin;
      int end;
      int length;
  
  };
  
  int findMax(int left, int right, int cross)
  {
  
      int max;
      if(left &gt; right &amp;&amp; left &gt; cross)
      {
          max = left;
      }
  
      else if(right &gt; left &amp;&amp; right &gt; cross)
      {
          max = right;
      }
  
      else
      {
          max = cross;
      }
  
      return(left, right, cross);
  }
  </code></pre>