Created
August 6, 2020 10:26
-
-
Save cs-fedy/a94659c8cc56ef08853af8229ac0512b to your computer and use it in GitHub Desktop.
Given a balanced expression that can contain opening and closing parenthesis, check if the expression contains any duplicate parenthesis or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a balanced expression that can contain opening and closing parenthesis, | |
// check if the expression contains any duplicate parenthesis or not. | |
unsigned is_duplicated(char str[], stck * st) { | |
int index = 0; | |
char ch; | |
while (str[index] != '\0') { | |
ch = str[index]; | |
if (ch != ')') | |
push(ch, st); | |
else { | |
if (get_peek(*st) == '(') | |
return 1; | |
while (get_peek(*st) != '(') | |
pop(st); | |
} | |
pop(st); | |
index++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment