Skip to content

Instantly share code, notes, and snippets.

@cs-fedy
Created August 6, 2020 10:26
Show Gist options
  • Save cs-fedy/a94659c8cc56ef08853af8229ac0512b to your computer and use it in GitHub Desktop.
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.
// 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