title: Connected Component Labeling - Implementation
body: <p>I have asked a similar question some days ago, but I have yet to find an efficient way of solving my problem.
  I'm developing a simple console game, and I have a 2D array like this:</p>
  
  <pre><code>1,0,0,0,1
  1,1,0,1,1
  0,1,0,0,1
  1,1,1,1,0
  0,0,0,1,0
  </code></pre>
  
  <p>I am trying to find all the areas that consist of neighboring 1's (4-way connectivity). So, in this example the 2 areas are as following:</p>
  
  <pre><code>1
  1,1
    1
  1,1,1,1
        1
  </code></pre>
  
  <p>and :</p>
  
  <pre><code>       1
       1,1
         1
  </code></pre>
  
  <p>The algorithm, that I've been working on, finds all the neighbors of the neighbors of a cell and works perfectly fine on this kind of matrices. However, when I use bigger arrays (like 90*90) the program is very slow and sometimes the huge arrays that are used cause stack overflows.</p>
  
  <p>One guy on my other question told me about connected-component labelling as an efficient solution to my problem.</p>
  
  <p>Can somebody show me any C++ code which uses this algorithm, because I'm kinda confused about how it actually works along with this disjoint-set data structure thing...</p>
  
  <p>Thanks a lot for your help and time.</p>