| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 518 人关注过本帖
标题:括号的匹配,求大神指导哪里错了,总是会显示缺少右括号
只看楼主 加入收藏
水若寒333
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-4-1
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
括号的匹配,求大神指导哪里错了,总是会显示缺少右括号
# include <string.h>
# include <ctype.h>
# include <malloc.h>
# include <limits.h>
# include <stdio.h>
# include <stdlib.h>
# include <io.h>
# include <math.h>
# include <process.h>
# include <iostream.h>
# define TRUE 1
# define FALSE 0
# define OK 1
# define ERROR 0
# define INFEASIBLE -1
typedef int Status;
typedef int Boolean;
#define STACK_INIT_SIZE 10
#define STACKINCREMENT 2
struct SqStack
{
 SElemType *base;
 SElemType *top;
 int stacksize;
};
Status InitStack(SqStack &S)
{
 if(!(S.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType))))
     exit(OVERFLOW);
 S.top=S.base;
 S.stacksize=STACK_INIT_SIZE;
 return OK;
}
Status StackEmpty(SqStack S)
{
  if(S.top==S.base)
      return OK;
  else
      return ERROR;
 }
Status push(SqStack &S,SElemType e)
{
 if(S.top-S.base>=S.stacksize)
 {
  S.base=(SElemType *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType));
  if(!S.base)
      exit(OVERFLOW);
    S.top=S.base+S.stacksize;
    S.stacksize+=STACKINCREMENT;
 }
 *(S.top)++=e;
  return OK;
 
}
Status pop(SqStack &S,SElemType &e)
{
if(S.top==S.base)
return ERROR;
e=*--S.top;
return OK;

}
typedef char SElemType;
#include "c1.h"
#include "c3.h"

void check()
{
    SqStack s;
    SElemType ch[80],*p,e;
    if(InitStack(s))
    {
        printf("请输入表达式\n");
        gets(ch);
        p=ch;
        while(*p)
        {
            switch(*p)
            {  
             case '(':
             case '[':push(s,*p++);break;
             case ')':
             case ']':if(s.base!=s.top  )
                     {
                         pop(s,e);
                         if(e=='['&&*p!=']'||e=='('&&*p!=')')
                         {
                             printf("左右括号不配对\n");
                             exit(ERROR);
                         }
                         else
                         {   p++;
                             break;
                         }
                     }
                     else
                     {
                       printf("缺乏左括号\n");
                       exit(ERROR);
                     }
                     break;
            default:
                p++;
                break;
            }
        
         if(s.base==s.top)
            printf("括号配对\n");
         else
            printf("缺乏右括号\n");
        }
    }
}

void main()
{check();}
搜索更多相关主题的帖子: include 
2014-04-01 23:52
hubinyes
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:104
专家分:557
注 册:2014-2-4
收藏
得分:10 
2014-04-02 15:59
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:10 
沙发可以不

同学习......同进步....你帮我......我帮你.....上善若水.....
2014-04-02 16:47
快速回复:括号的匹配,求大神指导哪里错了,总是会显示缺少右括号
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027260 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved