0% found this document useful (0 votes)
16 views4 pages

Practical No.9

Uploaded by

Paras Kamble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Practical No.9

Uploaded by

Paras Kamble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No: 09(Group D)

Name:
Name:Swapnil ManishKamble
Paras Chandan Suryawanshi
Class: SE
Div: C
Batch: C3
Roll
RollNo:S213074
No:S213085

Problem Statement: In any language program mostly syntax error occurs due to
unbalancing delimiter such as (),{},[]. Write C++ program using stack to check
whether given expression is well parenthesized or not.
CODE:-
Code:
#include<iostream>
#include<string.h>
using namespace std;
class Braces{ char
stack[20]; int top;
public: Braces(){ top
= -1;

void push(char a){ if (top>=19){


cout<<"Stack
overflowed"<<endl;

stack[top]=a;

void pop(){
if(top==-l){ cout<<"stack is
empty"<<endl;
}top--;

bool isempty(){
if(top==-l)
return true;
else return
false;

void input(){ char ch[20];


cout<<"Enter the
expression"<<endl; cin>>ch; int i=O;
while(i<strlen(ch))

{if (ch[i]- l lch[i]—


{push (ch[i]);} if(ch[i]==')'){ if (top!=-l
&& pop();} else
cout<<"Opening Matching bracket
not

found"<<endl;
if(ch[i]=='}'){ if (top!=-l &&
pop();} else cout<<"Opening Matching
bracket not

found"<<endl;
if (top!=-l && pop();} else
cout<<"Opening Matching bracket
not

found"<<endl;

if(isempty()==true) cout<<"Expression is properly


parenthesised"<<endl; else{while(isempty()== false)
{if(stack[top]=='(') cout<<"closing ) bracket not
if(stack[top]=='{') cout<<"closing } bracket
not if(stack[top]=='[') cout<<"closing ]
bracket not found"<<endl;
pop();}}

int main(){
Braces bl;
bl.input();
return O;

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy