以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 计算机考研交流 』   (http://bbs.xml.org.cn/list.asp?boardid=67)
----  [问题]可重复访问的广义表周游算法  (http://bbs.xml.org.cn/dispbbs.asp?boardid=67&rootid=&id=30548)


--  作者:yapi
--  发布时间:4/14/2006 8:24:00 AM

--  [问题]可重复访问的广义表周游算法
 即书上的第379页,代码如下
标红色的那一句作用是什么呢?
为什么对于仅有表头的空子表要立刻恢复mark呢?
不是都放在收尾处一并恢复的么?

public void traverseRE(GenListNode node ,int visitTime)
  {
  GenListNode p=node;
  //for HEAD ,maybe it is a re-visit list
  if(p.type==HEAD)
  {  p.mark=VISITED;
   //if it is already visited, just print out the head name
   if(p.visitTime>visitTime)
    Console.Write(p.name);
   else
   {  // " :( " means expand it
    Console.Write(p.name+" :(");
    p.visitTime++;
    //head node's next is just the real elements
    if(p.next!=null)
     traverseRE(p.next,visitTime);
    else  //if it is an empty head node, recover its mark
     p.mark=UNVISTED;//what does there matter ?
    Console.Write(" ) ");
     
   }
  
  
  }
  else
  if(p.type==ATOM)
   {
    Console.Write(p.element);
    p.mark=VISITED;
   
   }
  else
  if(p.type==LIST)
   traverseRE(p.child,visitTime);
  //recurse for the rest of the list
  if((p.next!=null)&&(p.next.mark!=VISITED))
  {
   Console.Write(" , ");
   p.mark=VISITED;
   traverseRE(p.next,visitTime);
  }
  //finally recover the mark for re visit
  GenListNode tmp=p;
  while(tmp!=null)
  {
  tmp.mark=UNVISITED;
  tmp=tmp.next;
  }
   
   
   
 
  
  
  
  
  
  }


[此贴子已经被作者于2006-4-14 12:13:27编辑过]

--  作者:datoubaicai
--  发布时间:4/18/2006 12:26:00 PM

--  
你这个ID好熟悉啊,,,
你是南开的?不是考上了吗?
--  作者:yapi
--  发布时间:4/23/2006 10:19:00 AM

--  
呵呵
我的两个同学都考上了



--  作者:yapi
--  发布时间:4/23/2006 3:54:00 PM

--  
今天把这个算法看明白了,是对的
上次漏看一个{},呵呵

public void traverseRE(GenListNode node ,int visitTime)
   {
   GenListNode p=node;
   //for HEAD ,maybe it is a re-visit list
   if(p.type==HEAD)
   {  p.mark=VISITED;
    //if it is already visited, just print out the head name
    if(p.visitTime>visitTime)
     Console.Write(p.name);
    else
    {  // " :( " means expand it
     Console.Write(p.name+" :(");
     p.visitTime++;
     //head node's next is just the real elements
     if(p.next!=null)
      traverseRE(p.next,visitTime);
     else  //if it is an empty head node, just recover its mark and go
     p.mark=UNVISTED;
     Console.Write(" ) ");
      
    }
   
   
   }
   else
{
   if(p.type==ATOM)
    {
     Console.Write(p.element);
     p.mark=VISITED;
    
    }
   else
   if(p.type==LIST)
    traverseRE(p.child,visitTime);
   //recurse for the rest of the list
   if((p.next!=null)&&(p.next.mark!=VISITED))
   {
    Console.Write(" , ");
    p.mark=VISITED;
    traverseRE(p.next,visitTime);
   }
}
   //finally recover the mark for re visit
   GenListNode tmp=p;
   while(tmp!=null)
   {
   tmp.mark=UNVISITED;
   tmp=tmp.next;
   }
    
    
    
  
   
   
   
   
   
   }


[此贴子已经被作者于2006-4-14 12:13:27编辑过]

[/quote]
--  作者:datoubaicai
--  发布时间:4/23/2006 5:24:00 PM

--  
哎,偶也没考上啊,
好象有个南开的考了第一名
你打算在哪复习考试啊?
--  作者:datoubaicai
--  发布时间:4/23/2006 5:28:00 PM

--  
我今年打算去北京复习,你如果也在北京复习的话,联系一下吧呵呵
我QQ:153976758
手机:13632494096
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms