Stack: WHT to solve bracket matching problems

Source: Internet
Author: User

#include <iostream>
using namespace Std;
#define STACKSIZE 100;
struct stack
{
Char Strstack[stacksize];
int top;
};
void Initstack (Stack &s)
{
S.top=-1;
}
Char push (Stack &s,char a)
{
if (s.top==stacksize-1)
return 0;
s.top++;
S.strstack[s.top]=a;
return A;
}
Char pop (Stack &s)
{
if (S.pop==-1) return 0;
Char A=s.strstack[s.top];
s.top--;
return 0;
}
int empty (stack &s,int re)
{
if (s.top==-1) return 1;
else return 0;
}
int check (CHAR*STR)
{
Stack s;
INITSTACKJ (s);
int Strn=strlen (str);
for (int i=0;i<strn;i++)
{
Char A=str[i];
Switch (a)
{
Case ' (';
Case ' {';
Case ' [';
Push (S,A);
Break
Case ') ';
if (pop (s)! = ' (') return 0;
Break
Case '} ';
if (pop (s)! = ' {') return 0;
Break
Case '] ';
if (pop (s)! = ' {') return 0;
Break
}
}
int re=0;
Re=empty (S,re); return 1;
else return 0;
}
void Main ()
{
Char str[100];
cin>>str;
int Re=check (str);
if (re==1)
cout<< "yes";
else if (re==0)
cout<< "No";
System ("pause");
return 0;
}

What's wrong with this program?

Please help the great gods.

Stack: WHT to solve bracket matching problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.