title: How Can You Clear a Quad Tree Without Recursion ( using queue maybe? )
body: <p>Ok given a class along the lines of </p>
  
  <pre><code>class quadTree {
   short level;
   Vec2f midpoint;
   quadTree * nodes[4] = { NULL, NULL, NULL, NULL};
  
  public:
  
  void newPartition() {
   float j = fWIDTH  / 2 ^ level;
   float k = fHEIGHT / 2 ^ level;
    nodes[0] = new quadTree(level+1, midpoint[0] - j, midpoint[0] + k);
    nodes[1] = new quadTree(level+1, midpoint[0] + j, midpoint[0] + k);
    nodes[2] = new quadTree(level+1, midpoint[0] - j, midpoint[0] - k);
    nodes[3] = new qaudTree(level+1, midpoint[0] + j, midpoint[0] - k);
   }
  }
  </code></pre>
  
  <p>How could I implement a function that deletes all the nodes under the current node of the quad tree without recursion probably using a queue? As in a Clear() function.</p>
  
  <p>I'm sorry for asking, I feel like I should know this and just can't quite figure it out. I looked online but couldn't find anything. Any Ideas?</p>
  
  <p>For any example code using a queue just use std::queue.</p>
  
  <p>EDIT :: 
  Ok I think this is what I am going to use for reference. I think this should work, correct me if I am wrong.</p>
  
  <pre><code>#include &lt;queue&gt;
  void helpClear( bool notPassing, queue&lt;quadTree&gt; &amp;q ) {
  int count;
  for ( int i; i &lt; 4; i++ ) {
   if ( node[i] != NULL){
    q.push ( node[i] );
    count++;
   }
  }
  quadTree * Point;
  if ( notPassing ){
   for ( int i; i &lt; count; i++ ){  
    Point = q.front();
    q.pop();
    Point -&gt; helpClear(0, q);   
  }
   for ( int i; i &lt; 4; i ++ )
     delete nodes[i]; 
  }
  }
  
  void clear () {
    queue &lt;quadTree&gt; q;
    quadTree * Point;
    helpClear(1,q);
    while (!queue.empty() ) {
      quadTree * Point;
      Point = q.front();
      q.pop();
      Point -&gt; helpClear(1,q);
      delete Point;
    }
  for ( int i; i &lt; 4; i++ )
      nodes[i] = NULL;
  }
  </code></pre>
  
  <p>helpClear() is a private function of quadTree and clear() is the public function you call to delete all nodes below the current node.</p>