Advertisement
Guest User

main.c

a guest
Oct 14th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "stack.h"
  4. #include "array.h"
  5.  
  6. int main(int argc, char** argv) {
  7. char equazione[100];
  8. int i=0, count=0;
  9. scanf("%s", equazione);
  10.  
  11. T_Stack tonde=create_stack();
  12. T_Stack quadre=create_stack();
  13. T_Stack graffe=create_stack();
  14. while(equazione[i]!='\0'){
  15. switch (equazione[i]){
  16. case '(':
  17. push(&tonde,equazione[i]);
  18. break;
  19. case '[':
  20. push(&quadre,equazione[i]);
  21. break;
  22. case '{':
  23. push(&graffe,equazione[i]);
  24. break;
  25. case ')':
  26. if(top(&tonde)=='('){
  27. pop(&tonde);
  28. break;
  29. }
  30. else{
  31. printf("non bilanciata");
  32. return 0;
  33. }
  34. case ']':
  35. if(top(&quadre)=='['){
  36. pop(&quadre);
  37. break;
  38. }
  39. else{
  40. printf("non bilanciata");
  41. return 0;
  42. }
  43. case '}':
  44. if(top(&graffe)=='{'){
  45. pop(&graffe);
  46. break;
  47. }
  48. else{
  49. printf("non bilanciata");
  50. return 0;
  51. }
  52. }
  53. i++;
  54. }
  55. if(is_empty(&tonde) && is_empty(&quadre) && is_empty(&graffe))
  56. printf("bilanciato");
  57. else printf("non bilanciata");
  58. return (EXIT_SUCCESS);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement