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

    >> 研友的交流园地,讨论关于计算机考研的方方面面。
    [返回] 计算机科学论坛计算机理论与工程『 计算机考研交流 』 → 今天写的两个算法 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3384 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 今天写的两个算法 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     yapi 帅哥哟,离线,有人找我吗?处女座1983-9-9
      
      
      等级:大一(高数修炼中)
      文章:27
      积分:187
      门派:XML.ORG.CN
      注册:2006/4/11

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给yapi发送一个短消息 把yapi加入好友 查看yapi的个人资料 搜索yapi在『 计算机考研交流 』 的所有贴子 引用回复这个贴子 回复这个贴子 查看yapi的博客楼主
    发贴心情 今天写的两个算法

    广义表删除原子和逆置,在sharp develop2.0下调试通过
    详见习题集p320 11.1,p309 11.4
    都是基于可重复访问的框架写的,看来正确的算法框架很重要啊。
    public void deleteRE(GenListNode p ,GenListNode pre,char x,int visitTime)
      {
       
      
      if(p.type==HEAD)  //HEAD
      {  p.mark=VISITED;
       if(p.visitTime>visitTime)  //already visited
       {
       }
       else
       {  
        p.visitTime++;
        //head node's next is just the real elements
        if(p.next!=null)
         deleteRE(p.next,p,x,visitTime);
          else    //empty head ,clear the mark
         p.mark=UNVISITED;  
      ;
         
       }
      
      
      }
      else  //ATOM or LIST
      {
       if(p.type==ATOM)
       {
        if(p.element==x)
        {pre.next=p.next;
         p=pre;
        }
        p.mark=VISITED;
       
       }
      else
      if(p.type==LIST)
       deleteRE(p.child,p,x,visitTime);
      //deal with the rest of the list
      if((p.next!=null)&&(p.next.mark!=VISITED))
      {
          
       p.mark=VISITED;   //recurse one by one
       deleteRE(p.next,p,x,visitTime);
      }
      }
      //clear the mark in the list
      GenListNode tmp=p;
      while(tmp!=null)
      {
      tmp.mark=UNVISITED;
      tmp=tmp.next;
      } 
      
      }
      
      
      
     
      /// <summary>
      /// reverse the elements in a genlist
      /// </summary>
      /// <param name="p"></param>
      /// <returns></returns>
      public GenListNode reverseRE(GenListNode p,GenListNode pre,int visitTime)  //return the new first
      {   GenListNode tmp,first,tail;
       if(p==null) return null;
       
       p.mark=VISITED;
       
       if(p.type==HEAD)
       {  if(p.visitTime<=visitTime)
        { p.visitTime++;
        p.next=reverseRE(p.next,p,visitTime);
        }
       }
       else
       {  //LIST
       if(p.type==LIST&&p.child.mark==UNVISITED)
       reverseRE(p.child,null,visitTime);
       ///about next of LIST or ATOM
        if(p.next==null) return p;
        else  //got next's new first
        first=reverseRE(p.next,p,visitTime);
        p.next=null;
       pre.next=first;
       //got tail
       tail=first;
       while(tail.next!=null) tail=tail.next;
       tail.next=p;
       
          p=first;
      
       
      }
       
       tmp=p;
      while(tmp!=null)
      {
      tmp.mark=UNVISITED;
      tmp=tmp.next;
      }
      //ultimate return value
      return p;
       }

       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    宁静以致远,淡薄以铭志

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/4/23 16:00:00
     
     Logician 帅哥哟,离线,有人找我吗?天蝎座1984-10-28
      
      
      威望:9
      头衔:逻辑爱好者
      等级:研三(收到IBM CRL的Offer了)(版主)
      文章:1219
      积分:10357
      门派:IEEE.ORG.CN
      注册:2005/3/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Logician发送一个短消息 把Logician加入好友 查看Logician的个人资料 搜索Logician在『 计算机考研交流 』 的所有贴子 点击这里发送电邮给Logician  访问Logician的主页 引用回复这个贴子 回复这个贴子 查看Logician的博客2
    发贴心情 
    用sharp develop。听上去不错啊!呵呵。

    ----------------------------------------------
    Three passions, simple but overwhelmingly strong, 
    have governed my life: the longing for love, the
    search for knowledge, and unbearable pity for the
    suffering of mankind.
                                - Bertrand Russell

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/4/23 21:32:00
     
     GoogleAdSense天蝎座1984-10-28
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 计算机考研交流 』 的所有贴子 点击这里发送电邮给Google AdSense  访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/16 21:31:00

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

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