Course Solutions Uncategorized (Solved) : Exercise 45 10 Points Write Program C C Receive Character String Keyboard Maximum Length 1 Q30120708 . . . .

(Solved) : Exercise 45 10 Points Write Program C C Receive Character String Keyboard Maximum Length 1 Q30120708 . . . .

 

Exercise 4.5 (10 points)

   Write an program(c or c++) to receive a characterstring from the keyboard(the maximum length is 100), and testwhether the brackets ()?[]?{}in the string arematching.

typedef char SElemType;

Status BracketsMatching(char s[])

{

               SqStack S;

               char c;

               char e;

InitStack(S);

for(i=0, c=s[i]; c!=’ ’; ++i, c=s[i])

{

       if(c==’(’ || c==’[’ || c==’{’)

                      Push(S, c);

       elseif (c==’)’ || c==’]’ ||c ==’}’)

       {

                      add some codes here

       }

}

}

int main()

{

               char c;

               char s[100];

               int len=0;

               c=getchar();

               

while(c!=’#’) // ‘#’ means the end of string

               {

                               s[len++]=c;            

                               c=getchar();            

               }

               s[len]=’ ’;

               if(BracketsMatching(s)==TRUE)

                               printf(“the brackets in the string are matching”);

               else

                               printf(“the brackets in the string are not matching”);

}

Expert Answer


An answer will be send to you shortly. . . . .

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post