Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#define BUFSIZE 1000 #include static char buf[BUFSIZE];//buffer for opening symbols static int bufp;//next free position in buf void push(char c){ buf[bufp] = c; bufp++; }

#define BUFSIZE 1000

#include

static char buf[BUFSIZE];//buffer for opening symbols

static int bufp;//next free position in buf

void push(char c){

buf[bufp] = c;

bufp++;

}

char pop(void){

if(is_empty())

return '\0';

bufp--;

return buf[bufp];

}

char peek (void){

if(is_empty())

return '\0';

return buf[bufp - 1];

}

int is_empty(){

return !bufp;//bufp == 0

}

int size(){

return bufp;

}

int is_opening_symbol(char c){//linear search

extern char opening_symbol[];

int len = strlen(opening_symbol);

for(int i = 0;i < len;i++)

if(c == opening_symbol[i])

return 1;

return 0;

}

int is_closing_symbol(char c){//linear search

extern char closing_symbol[];

int len = strlen(closing_symbol);

for(int i = 0;i < len;i++)

if(c == closing_symbol[i])

return 1;

return 0;

}

int is_matched(char open, char close){

//your code here...

return 1;

}

int check(char input[]){

bufp = 0;//empty out the stack!

int len = strlen(input);

for(int i = 0; i < len;i++){

if(is_opening_symbol(input[i]))

push(input[i]);

else if(is_closing_symbol(input[i])){

//match operation: First pop c, then

//find out whether c and input[i] match

//if not matched, then return 0;//not balanced

//else keep going

char c = pop();

if(!is_matched(c, input[i]))

return 0;

}else{

continue;

}

/*switch(input[i]){

case '(':case '[':

push(input[i]);

break;

case ')':

if(pop() != '(')

return 0;//unbalanced

break;

case ']':

if(pop() != '[')

return 0;//unbalanced

break;

default:

;

}*/

}

return is_empty();

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the various techniques of Management Development.

Answered: 1 week ago