1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#include <stdio.h> #include <conio.h> struct stak{ int top; char data_array[100]; }string; void pop(){ string.top--; } void push(){ string.top++; } void check_if_balanced(char equation[]); void main(){ char equation[20]; clrscr(); printf("Enter any equation\n"); gets(equation); check_if_balanced(equation); getch(); } void check_if_balanced(char equation[]){ int i=0,j=0,iseven=0; string.top=-1; while(equation[i]){ if(equation[i]=='(' ||equation[i]=='{'||equation[i]=='['){ push(); string.data_array[j]=equation[i]; j++; iseven++; } if(equation[i]==')'||equation[i]==']'||equation[i]=='}'){ switch(equation[i]){ case ')': iseven--; if(string.data_array[j-1]=='('){ pop(); j--;} break; case ']': iseven--; if(string.data_array[j-1]=='[' ){ pop(); j--;} break; case '}': iseven--; if(string.data_array[j-1]=='{'){ pop(); j--;} break; default: break; } } i++; } // End of while if(string.top==-1 && iseven==0) printf("\nBalanced\n"); else printf("\nNot Balanced\n"); } // end of function |
Java
Java Applet Of Moving Plane
“applet” class [crayon-5a2bba9c5b979052461798/] HTML File [crayon-5a2bba9c5b988449425286/] How to Run After compilation you can use “appletviewer” to run your applet. appletviewer xyz.html