Update a1/program.c
This commit is contained in:
parent
8bf0959328
commit
7d962d4d38
13
a1/program.c
13
a1/program.c
@ -16,6 +16,14 @@ int isMatching(char open, char close) {
|
||||
(open == '<' && close == '>');
|
||||
}
|
||||
|
||||
char expectedClosing(char open) {
|
||||
if (open == '{') return '}';
|
||||
if (open == '[') return ']';
|
||||
if (open == '(') return ')';
|
||||
if (open == '<') return '>';
|
||||
return '\0';
|
||||
}
|
||||
|
||||
int main() {
|
||||
char input[101];
|
||||
char stack[100];
|
||||
@ -54,8 +62,9 @@ int main() {
|
||||
}
|
||||
|
||||
if (top != -1) {
|
||||
printf("Missing closing brackets: %c\n", stack[top]);
|
||||
return 0;
|
||||
char expected = expectedClosing(stack[top]);
|
||||
printf("Missing closing brackets: %c\n", expected);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("All brackets OK\n");
|
||||
|
Loading…
Reference in New Issue
Block a user