Esempio n. 1
0
bool MainWindow::isRightBrackets(QString &st, StackType type) {
    ArrayStack<QChar> aStack(MAX_STACK_SIZE);
    ListStack<QChar> lStack;

    Stack<QChar> *stack;
    if (type == Array)
        stack = &aStack;
    else
        stack = &lStack;

    LOG;
    for (int i = 0; i < st.length(); i++) {
        if ((st[i] == '{') || (st[i] == '}') || (st[i] == '[') || (st[i] == ']') ||
                (st[i] == '(') || (st[i] == ')'))
        {
            if (isOpeningBracket(st[i])) {
                stack->Push(st[i]);
                LOG;
            }
            else {
                if (stack->isEmpty())
                    return false;
                if ((matchingBrackets(stack->Top(), st[i]))) {
                    LOG;
                    stack->Pop();
                    LOG;
                } else {
                    stack->Free();
                    return false;
                }
            }
        }
    }

    bool Result = true;
    if (!(stack->isEmpty())) {
        Result = false;
        stack->Free();
        LOG;
    }
    return Result;
}