First blog - using the "stack" in parenthesis matching algorithm


bool BracketsCheck(char *str){
  InitStack(S);
  int i=0;
  while(str[i]!='\0'){
    switch(str[i]){
    case'(':Push(S,str[i]);break;
    case'[':Push(S,str[i]);break;
    case'{':Push(S,str[i]);break;
    case')':
      Pop(S,e);
      if(e!='(')return false;
      break;
    case']':
      Pop(S,e);
      if(e!='[')return false;
      break;
    case'}':
      Pop(S,e);
      if(e!='{')return false;
      break;
    default:break;
    }
    i++;
  }//while
  if(!The IsEmpty (S)) {
    the printf ( "right parenthesis \ n");
    to false return;
  }
  the else {
    the printf ( "matching brackets \ n-");
    return to true;
  }
}

Guess you like

Origin www.cnblogs.com/hao-x/p/Milk_exe.html