新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     >>计算机科学论坛<<     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 计算机科学论坛计算机技术与应用『 C/C++编程思想 』 → [讨论]为何求深度会出现时会出现debug error! 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 4092 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [讨论]为何求深度会出现时会出现debug error! 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     oceanblue 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:12
      积分:137
      门派:XML.ORG.CN
      注册:2005/5/2

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给oceanblue发送一个短消息 把oceanblue加入好友 查看oceanblue的个人资料 搜索oceanblue在『 C/C++编程思想 』的所有贴子 引用回复这个贴子 回复这个贴子 查看oceanblue的博客楼主
    发贴心情 [讨论]为何求深度会出现时会出现debug error!

    #define HEAD 0
    #define INTGR 1             
    #define CH 2
    #define LST 3
    #define NULL 0
    #include <iostream.h>
    #include <stdlib.h>
    #include<string.h>
    class GenList;
    class GenListNode
    {
     friend class GenList;
        private:
     int utype;
     GenListNode *tlink;
     union
     {
      int ref;
      int intginfo;
      char charinfo;
      GenListNode *hlink; }value;
     public:
        
     
      int nodetype(GenListNode *elem)
      {
       return elem->utype;
      }
              int Getvalue()const
      {
              return utype;
      }
      
    };
    class GenList
    {
    private:    GenListNode* first;

     void Remove(GenListNode *ls);
    public:   friend ostream &operator<<(ostream& out,const GenList &outlist);

     //friend int operator==(const GenList &l,const GenList &m);
     GenList();

     GenListNode &Head();
     GenListNode &Tail();
     GenListNode *First();
     GenListNode *Next(GenListNode *elem);
     void Push(GenListNode &x);   virtual int depth(GenListNode *ls);

     int Createlist(GenListNode *&ls,char *s);
     int sever(char *&str1,char *&hstr1);
    };
    GenList::GenList()
    {
     GenListNode *first=new GenListNode;
     first->utype=0;
     first->value.ref=1;
     first->tlink=NULL;
     
    }
    GenListNode& GenList::Head()
    {
     if(first->tlink==NULL)
     {
      cout<<"Illegal head operation."<<endl;
      exit(1);
     }
     else
     {
      GenListNode *temp=new GenListNode;
      temp->utype=first->tlink->utype;
      temp->value=first->tlink->value;
      return *temp;
     }
    }
    GenListNode& GenList::Tail()
    {
     if(first->tlink==NULL)
     {
      cout<<"Illegal tail operation."<<endl;
      exit(1);
     }
     else
     {
      GenList*temp=new GenList;
      temp->first->tlink=first->tlink->tlink;
      return *temp->first;
     }
    }
    GenListNode *GenList::First()
    {
     if(first->tlink==NULL)return NULL;
     else return first->tlink;
    }
    GenListNode *GenList::Next(GenListNode *elem)
    {
     if(elem->tlink==NULL)return NULL;
     else return elem->tlink;
    }
    void GenList::Push(GenListNode &x)
    {
     if(first->tlink==NULL)first->tlink=x.tlink;
     else
     {
      x.tlink=first->tlink;
      first->tlink=x.tlink;
      
     }
    }

    int GenList::depth(GenListNode *ls)

    {

     if(ls->tlink==NULL)return 1;

     GenListNode *temp=ls->tlink;

     int m=0;

     while(temp!=NULL)

     {

      if(temp->utype==LST)

      {

       int n=depth(temp->value.hlink);

       if(m<n)m=n;

      }

      temp=temp->tlink;

     }

     return m+1;

    }

    int GenList::Createlist(GenListNode * &ls,char *s)
    {
        char *sub,*hsub;

     ls=new GenListNode();
     ls->utype=HEAD;
     ls->value.ref=1;
     
     if(strlen(s)==0||!strcmp(s,"()"))ls->tlink=NULL;
     else
     {    
      sub=new char[strlen(s)-2];        
                    strncpy(sub,s+1,strlen(s)-2);        
      
      GenListNode *p=ls;

      while(strlen(sub)!=0)

      {

       p=p->tlink=new GenListNode();

       if(sever(sub,hsub))

       {    
                     
        
        if(hsub[0]!='('&&hsub[0]!='\'')
        {

         p->utype=INTGR;
                      
          p->value.intginfo=atoi(hsub);
            cout<<"free digital"<<p->value.intginfo<<endl;
                       
        }

        else if(hsub[0]!='('&&hsub[0]=='\'')

        {
         p->utype=CH;
                       
         p->value.charinfo=hsub[1];
         
         cout<<"free char"<<p->value.charinfo<<endl;
        }

        else

        {
                       
         p->utype=LST;
                
         Createlist(p->value.hlink,hsub);

        }

       }

       else return 0;

      }

      p->tlink=NULL;

         
     
     }

     return 1;
     
    }
    int GenList::sever(char *&str1,char * &hstr1)

    {

     char ch=str1[0];

     int n=strlen(str1);

     int i=0,k=0;
        
     while(i<n&&(ch!=','||k!=0))

     {

      if(ch=='(')k++;

      else if(  ch == ')')k--;

      i++;

      ch=str1[i];

     }

     if(i<n)
     {   
      hstr1=new char[i];

      strncpy( hstr1 , str1 , i);
              
      strncpy(str1 , str1+i+1 , n-i+1 );

           cout<<hstr1<<endl;

      return 1;

     }
     else if(k!=0)return 0;
     
     else
     {
         hstr1=new char[strlen(str1)+1];
      
      strcpy( hstr1 , str1 );
            
      str1[0] = '\0';

      return 1;
     }

     

    }

    void main()
    {
    char *str="(2,('b',7),(3),('d'))";
    GenList aa;
    GenListNode * bb;
    aa.Createlist(bb,str);
    cout<<aa.depth(bb);
    }


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/5/3 13:04:00
     
     oceanblue 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:12
      积分:137
      门派:XML.ORG.CN
      注册:2005/5/2

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给oceanblue发送一个短消息 把oceanblue加入好友 查看oceanblue的个人资料 搜索oceanblue在『 C/C++编程思想 』的所有贴子 引用回复这个贴子 回复这个贴子 查看oceanblue的博客2
    发贴心情 
    欢迎大家来讨论!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/5/3 13:07:00
     
     oceanblue 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:12
      积分:137
      门派:XML.ORG.CN
      注册:2005/5/2

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给oceanblue发送一个短消息 把oceanblue加入好友 查看oceanblue的个人资料 搜索oceanblue在『 C/C++编程思想 』的所有贴子 引用回复这个贴子 回复这个贴子 查看oceanblue的博客3
    发贴心情 
    #define HEAD 0
    #define INTGR 1             
    #define CH 2
    #define LST 3
    #define NULL 0
    #include <iostream.h>
    #include <stdlib.h>
    #include<string.h>
    class GenList;
    class GenListNode
    {
     friend class GenList;
        private:
     int utype;
     GenListNode *tlink;
     union
     {
      int ref;
      int intginfo;
      char charinfo;
      GenListNode *hlink; }value;
     public:
        
     
      int nodetype(GenListNode *elem)
      {
       return elem->utype;
      }
              int Getvalue()const
      {
              return utype;
      }
      
    };
    class GenList
    {
    private:    GenListNode* first;

     void Remove(GenListNode *ls);
    public:   friend ostream &operator<<(ostream& out,const GenList &outlist);

     //friend int operator==(const GenList &l,const GenList &m);
     GenList();

     GenListNode &Head();
     GenListNode &Tail();
     GenListNode *First();
     GenListNode *Next(GenListNode *elem);
     void Push(GenListNode &x);   virtual int depth(GenListNode *ls);

     int Createlist(GenListNode *&ls,char *s);
     int sever(char *&str1,char *&hstr1);
    };
    GenList::GenList()
    {
     GenListNode *first=new GenListNode;
     first->utype=0;
     first->value.ref=1;
     first->tlink=NULL;
     
    }
    GenListNode& GenList::Head()
    {
     if(first->tlink==NULL)
     {
      cout<<"Illegal head operation."<<endl;
      exit(1);
     }
     else
     {
      GenListNode *temp=new GenListNode;
      temp->utype=first->tlink->utype;
      temp->value=first->tlink->value;
      return *temp;
     }
    }
    GenListNode& GenList::Tail()
    {
     if(first->tlink==NULL)
     {
      cout<<"Illegal tail operation."<<endl;
      exit(1);
     }
     else
     {
      GenList*temp=new GenList;
      temp->first->tlink=first->tlink->tlink;
      return *temp->first;
     }
    }
    GenListNode *GenList::First()
    {
     if(first->tlink==NULL)return NULL;
     else return first->tlink;
    }
    GenListNode *GenList::Next(GenListNode *elem)
    {
     if(elem->tlink==NULL)return NULL;
     else return elem->tlink;
    }
    void GenList::Push(GenListNode &x)
    {
     if(first->tlink==NULL)first->tlink=x.tlink;
     else
     {
      x.tlink=first->tlink;
      first->tlink=x.tlink;
      
     }
    }

    int GenList::depth(GenListNode *ls)

    {

     if(ls->tlink==NULL)return 1;

     GenListNode *temp=ls->tlink;

     int m=0;

     while(temp!=NULL)

     {

      if(temp->utype==LST)

      {

       int n=depth(temp->value.hlink);

       if(m<n)m=n;

      }

      temp=temp->tlink;

     }

     return m+1;

    }

    int GenList::Createlist(GenListNode * &ls,char *s)
    {
        char *sub,*hsub;

     ls=new GenListNode();
     ls->utype=HEAD;
     ls->value.ref=1;
     
     if(strlen(s)==0||!strcmp(s,"()"))ls->tlink=NULL;
     else
     {       
           sub=new char[strlen(s)-1];        
                    strncpy(sub,s+1,strlen(s)-2);
        sub[strlen(s)-2]='\0';
      
      GenListNode *p=ls;

      while(strlen(sub)!=0)

      {

       p=p->tlink=new GenListNode();

       if(sever(sub,hsub))

       {    
                     
        
        if(hsub[0]!='('&&hsub[0]!='\'')
        {

         p->utype=INTGR;
                      
          p->value.intginfo=atoi(hsub);
            cout<<"free digital"<<p->value.intginfo<<endl;
                       
        }

        else if(hsub[0]!='('&&hsub[0]=='\'')

        {
         p->utype=CH;
                       
         p->value.charinfo=hsub[1];
         
         cout<<"free char"<<p->value.charinfo<<endl;
        }

        else

        {
                       
         p->utype=LST;
                
         Createlist(p->value.hlink,hsub);

        }

       }

       else return 0;

      }

      p->tlink=NULL;

         
     
     }

     return 1;
     
    }
    int GenList::sever(char *&str1,char * &hstr1)

    {

     char ch=str1[0];

     int n=strlen(str1);

     int i=0,k=0;
        
     while(i<n&&(ch!=','||k!=0))

     {

      if(ch=='(')k++;

      else if(  ch == ')')k--;

      i++;

      ch=str1[i];

     }

     if(i<n)
     {   
      hstr1=new char[i+1];

      strncpy( hstr1 , str1 , i);
             hstr1[i]='\0';
      strncpy(str1 , str1+i+1 , n-i+1 );
            str1[n-i+1]='\0';
           cout<<hstr1<<endl;

      return 1;

     }
     else if(k!=0)return 0;
     
     else
     {
         hstr1=new char[strlen(str1)+1];
      
      strcpy( hstr1 , str1 );
            
      str1[0] = '\0';

      return 1;
     }

     

    }

    void main()
    {
    char *str="(2,('b',7),(((3)),('d')))";
    GenList aa;
    GenListNode * bb;
    aa.Createlist(bb,str);cout<<aa.depth(bb);
    }
    ok,终于调出debug error

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/5/5 9:45:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/19 8:26:20

    本主题贴数3,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    109.375ms