Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "stack.h"
- #include "array.h"
- int main(int argc, char** argv) {
- char equazione[100];
- int i=0, count=0;
- scanf("%s", equazione);
- T_Stack tonde=create_stack();
- T_Stack quadre=create_stack();
- T_Stack graffe=create_stack();
- while(equazione[i]!='\0'){
- switch (equazione[i]){
- case '(':
- push(&tonde,equazione[i]);
- break;
- case '[':
- push(&quadre,equazione[i]);
- break;
- case '{':
- push(&graffe,equazione[i]);
- break;
- case ')':
- if(top(&tonde)=='('){
- pop(&tonde);
- break;
- }
- else{
- printf("non bilanciata");
- return 0;
- }
- case ']':
- if(top(&quadre)=='['){
- pop(&quadre);
- break;
- }
- else{
- printf("non bilanciata");
- return 0;
- }
- case '}':
- if(top(&graffe)=='{'){
- pop(&graffe);
- break;
- }
- else{
- printf("non bilanciata");
- return 0;
- }
- }
- i++;
- }
- if(is_empty(&tonde) && is_empty(&quadre) && is_empty(&graffe))
- printf("bilanciato");
- else printf("non bilanciata");
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement