我在检查括号字符串是否平衡的算法时遇到了一些问题。我必须从文本文件中获取输入并在另一个文本文件中显示输出。我遇到了这个算法的问题。请帮我找出问题
#include <iostream>
#include <string.h>
#include <fstream>
#include "stack.h"
#include "stack.cpp"
using namespace std;
int main() {
StackType<char> c;
ifstream inFile("parentheses.txt");
ofstream outFile("report.txt");
int i, N;
char str[500];
inFile >> N;
inFile >> str;
while (str[i]) {
for (int i = 0; str[i] != '\0'; i++) {
if ((str[i] == '(') || (str[i] == '{') || (str[i] == '[')) {
c.Push(str[i]);
} else if ((str[i] == ')') || str[i] == '}' || str[i] == ']') {
if (c.isEmpty() == 1)
outFile << "Parentheses are not Balanced" << endl;
else if ((str[i] == ')' && str[i] == '(') ||
(str[i] == '}' && str[i] == '{') ||
(str[i] == ']' && str[i] == '[')) {
c.Pop();
} else
outFile << "Parentheses are not Balanced" << endl;
}
}
i++;
}
if (c.isEmpty() == 1)
outFile << "Parentheses are Balanced" << endl;
else
outFile << "Parentheses are not Balanced" << endl;
}