title: Segmentation Fault in the implementation of a sorting function
body: <p>I am trying to implement a sorting algorithm based on psuedocode provided for my programming class and me and my partner have been consistently getting (core dumped) errors, usually Segmentation Fault specifically. I understand that usually means the program is trying to access memory it is not allowed to, but I'm unsure how to fix the issue.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  
  using namespace std;
  
  void FlipFlopSort(int *Array, int begin, int end){
      int length = (end-begin);
      float midh = 2*(float)length/3;
      midh = ceil(midh);
      float midl = (float)length/3;
      midl = ceil(midl);
      //cout &lt;&lt; "size of sorted area = " &lt;&lt; length &lt;&lt; endl;
      if(length&lt;=2){
          //cout &lt;&lt; "Length = 2" &lt;&lt; endl;
          if(Array[begin] &gt; Array[begin+1]){
              swap(Array[begin], Array[begin+1]);
          }
      }else{
          //cout &lt;&lt; "Recursion Begin 1" &lt;&lt; endl;
          FlipFlopSort(Array, begin, midh);
          //cout &lt;&lt; "Recursion End" &lt;&lt; endl;
          FlipFlopSort(Array, midl, end);
          //cout &lt;&lt; "Recursion Begin 2" &lt;&lt; endl;
          FlipFlopSort(Array, begin, midh);
      }
  }
  
  int main(){
      // Declare Variables and Read Inputs
      int n;
      cin &gt;&gt; n;
  
      int Array[n];
  
      for(int i = 0; i &lt; n; i++){
          cin &gt;&gt; Array[i];
      }
  
      FlipFlopSort(Array, 0, n);
  
  
      for(int i = 0; i&lt;n; i++){
           if(i != (n-1)){
               cout &lt;&lt; Array[i] &lt;&lt; " ";
           }else{
               cout &lt;&lt; Array[i] &lt;&lt; endl;
           }
      }
  
      return 0;
  
  }
  
  
  
  </code></pre>