Ensure parenthesis are balanced?
<p>I am tasked to create a function that checks if a number of small "(" and big "[" parentheses and closes properly. For example...</p>

<pre><code>(()) [] ([])[(())]
</code></pre>

<p>...is correct, but...</p>

<pre><code>() [(]) 
</code></pre>

<p>...is incorrect.</p>

<p>Any advice on how to start approaching this problem? The use of recursive functions is prohibited.</p>

<hr>

<p>This is what I have so far:</p>

<pre><code>{
    int nr_ap_x = 0; // fie x - "("
    int nr_ap_y = 0; // fie y - ")"
    boolean corect = true;

    for (int i=0; i &lt; sir.length; i++)
    {
        if (sir[i].compareTo("(") == 0) nr_ap_x++;
        else
            if (sir[i].compareTo(")") == 0) nr_ap_y++;
        if (nr_ap_x &lt; nr_ap_y) corect = false;
    }
    if (nr_ap_x != nr_ap_y) corect = false;
    if (corect) System.out.println("Parantezele sunt inchise corect ! ");
    else System.out.println("Parantezele NU sunt inchise corect ! ");
}
</code></pre>
