Ex12 Stack Array Bp

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Ex12 Stack Array Bp as PDF for free.

More details

  • Words: 107
  • Pages: 2
Ex. No : 12 BALANCED PARENTHESIS USING STACK ARRAY PROGRAM \*File Name : c:\bal1.c*\ #include<stdio.h> #include #include<string.h> static int top=0; struct stack { char exp[20]; }st; void push(char c) { ++top; st.exp[top]=c; } int pop() { int x=0; if(top>0) { --top; x=1; } return(x); } \* File name : c:\bal2.c*\ #include<stdio.h> #include #include<string.h> #include"c:\bal1.c" int eval(char s[20]) { int len,i,z,err=0; len=strlen(s); for(i=0;i<=(len-1);i++) { if(s[i]=='(')

push(s[i]); if(s[i]==')') { z=pop(); if(z==0) err=1; } } if ((pop()!=0)||(err==1)) return(1); else return(0); } \*File name : c:\bal3.c*\ #include<stdio.h> #include #include<string.h> #include"c:\bal2.c" void main() { char exp[20]; int f; clrscr(); printf("Enter the Expression"); scanf("%s",exp); f=eval(exp); if(f==1) printf("ERROR"); else printf("Expression is balanced"); getch(); }

Related Documents

Ex12 Stack Array Bp
October 2019 8
Stack Array
May 2020 6
Assign5 Stack Array
November 2019 6
Stack
May 2020 16
Stack
April 2020 21