codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include<stdio.h> #include<string.h> #include<stdlib.h> #include "Singly-LinkedList.c" #define MAX 30 int top=-1; int stack[MAX]; void push(char); char pop(); int match(char a,char b); int check(char []); int main() { SN *List=NULL; FILE *fn; fn=fopen("balanced.txt","r"); if(fn==NULL){ return 1; } char exp[MAX]; int valid; valid=check(exp); if(valid==1) return 1; else return 0; } int check(char exp[] ) { int i; char temp; for(i=0;i<strlen(exp);i++) { if(exp[i]=='(' || exp[i]=='{' || exp[i]=='[') push(exp[i]); if(exp[i]==')' || exp[i]=='}' || exp[i]==']') if(top==-1) { return 0; } else { temp=pop(); if(!match(temp, exp[i])) { printf("%c and %c\n",temp,exp[i]); return 0; } } } if(top==-1) { return 1; } else { return 0; } } int match(char a,char b) { if(a=='[' && b==']') return 1; if(a=='{' && b=='}') return 1; if(a=='(' && b==')') return 1; return 0; } void push(char item) { if(top==(MAX-1)) { return; } top=top+1; stack[top]=item; } char pop() { if(top==-1) { exit(1); } return(stack[top--]); }
Private
[
?
]
Run code
Submit