Program-7: AIM: Program To Check For Balance Parenthesis. Description
Program-7: AIM: Program To Check For Balance Parenthesis. Description
#include<stdlib.h>
struct sNode
{
char data;
struct sNode *next;
};
1|2k18/SE/014
while (exp[i])
{
if (exp[i] == '{' || exp[i] == '(' || exp[i] == '[')
push(&stack, exp[i]);
if (stack == NULL)
return 0;
if (stack == NULL)
return 1;
else
return 0;
}
int main()
{
char exp[100] = "{()}[]"; //input
if (areParenthesisBalanced(exp))
printf("Balanced \n");
else
printf("Not Balanced \n");
return 0;
}
if (new_node == NULL)
{
printf("Stack overflow n");
getchar();
exit(0);
2|2k18/SE/014
}
new_node->data = new_data;
new_node->next = (*top_ref);
(*top_ref) = new_node;
}
if (*top_ref == NULL)
{
printf("Stack overflow n");
getchar();
exit(0);
}
else
{
top = *top_ref;
res = top->data;
*top_ref = top->next;
free(top);
return res;
}
}
OUTPUT:
3|2k18/SE/014