算法问题:给高手送分哈(50分)

  • 主题发起人 主题发起人 seagull007
  • 开始时间 开始时间
S

seagull007

Unregistered / Unconfirmed
GUEST, unregistred user!
有两个数组ID[LENGTH], PID[LENGTH],对应存放ID号和父ID号,给定一个ID值,找出该ID的所有后代结点。咋 个写
 
我的数据结构差得很,知道的兄弟帮帮忙哈
 
是分太少了,还是题太简单了,高手都不愿意回答哦
 
function &nbsp;GetAllChild(ID:Integer;out childList:TStrings):Boolean;<br>var<br>&nbsp; I,J,nIndex:Integer;<br>&nbsp; IsExists:Boolean;<br>begin<br>&nbsp; IsExists:=False;<br>&nbsp; nIndex:=-1;<br>&nbsp; For I:=0 to Length(PIDARY)-1 do &nbsp; &nbsp; //判断是否存在<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;if (PIDARY = ID) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;IsExists:=True;<br>&nbsp; &nbsp; &nbsp; &nbsp;nIndex:=I;<br>&nbsp; &nbsp; &nbsp; &nbsp;Break;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; end;<br>&nbsp; if IsExists then<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;childList.Add(IntToStr(IDARY[nIndex])); //找到一个<br>&nbsp; &nbsp; &nbsp;GetAllChild(IDARY[nIndex],childList);<br>&nbsp; end<br>&nbsp; else<br>&nbsp; Result:=True;<br>end;
 
呵呵,谢谢,我试一下哈
 
后退
顶部