asp二叉树的应用

    最近要给一个搜索网站改搜索的算法,要求实在是…… 其中一个要求是精确查找,只是众多要求中的很小的功能,而且这些功能是相互联系的……够复杂的哈,哈哈``` 开始做吧。 先解决精确查找的问题,上星期想了一天没思路,今天想了一个早上,决定用二叉数搞定问题。JUST GO!!!

    首先用一个类吧

文件名:Cls.asp

内容:

<%
Class TreeNode

 Public LTreeNode '左节点
 Public Parent '父节点
 Public RTreeNode '右节点
 Public id
 Public title
 Public content
 Public url
 Public oicq
 Public email
 Public sort_path
 Public tim
 Public sequence
 Public address
 Public phone
 
 Private Sub Class_Initialize()
  Set LTreeNode = Nothing
  Set Parent = Nothing
  Set RTreeNode = Nothing
  id = 0
  title = ""
  content = ""
  url = ""
  oicq = ""
  email = ""
  sort_path = ""
  tim = ""
  sequence = 0
  address = ""
  phone = ""
 End Sub
 
 Public Function Init(nid, strtitle, strccontent, strurl, stroicq, stremail, strsort_path, strtim, nsequence, straddress, strphone)
  Set LTreeNode = Nothing
  Set Parent = Nothing
  Set RTreeNode = Nothing
  id = nid
  title = strtitle
  content = strcontent
  url = strurl
  oicq = stroicq
  email = stremail
  sort_path = strsort_path
  tim = strtim
  sequence = nsequence
  address = straddress
  phone = strphone
 End Function

End Class
%>

<%
' 前序输出
Function ShowTrees(ByRef Node)
 if Node is Nothing then
  exit Function
 end if
 
 '如果左子数不为Nothing
 if Not Node.LTreeNode is Nothing then
  Call ShowTrees(Node.LTreeNode)
 end if
 '输出结果
 Call DisplayCont(Node)
 
 '如果右子数不为Nothing
 if Not Node.RTreeNode is Nothing then
  Call ShowTrees(Node.RTreeNode)
 end if
End Function
%>

<%
'输出内容
Function DisplayCont(Node)
 response.Write "<table width='90%' border='0' cellspacing='0' cellpadding='0'>"
 response.Write "<tr>"
 response.Write "<td width=10>&nbsp;</td>"
 response.Write "<td width='70%'>"
 ' 标题
 response.write "<span style='font-size: 14px'><a href='goto.asp?id="&Node.id&"&url="&Node.url&"'  target='_blank'>"&replace(Node.title,keyword,"<font color=#FF0000>"&keyword&"</font>")&"</a></span>&nbsp;"
 '竟价排名显示
 if Node.sequence >= 200 and Node.sequence <= 300 then
  response.Write "<span style='color:#F59411'>黄金排名</span>"
 elseif Node.sequence >= 100 and Node.sequence < 200 then
  response.Write "<span style='color:#990000'>普通排名</span>"
 end if
 '时间
 response.Write " <font color=#666666>"&Node.tim&"</font>"
 
 response.Write "</td>"
 '
 response.Write "<td width='100'  valign=top>"
 if Node.oicq <> "" then
  response.Write " <font color=#0000FF> "+"<A class=txtcolor href='http://wpa.qq.com/msgrd?V=1&amp;Uin="&Node.oicq&"&amp;Exe=QQ&amp;Site=http://www.123qyw.cn/&amp;Menu=No' target=blank><IMG alt=点击交谈 src='http://wpa.qq.com/pa?p=1:"&Node.oicq&":"&QQTYPE&"' border=0></A>"+"</font> "
 else
  response.Write "&nbsp;"
 end if
 response.Write "</td>"
 response.Write "<td width='100' valign=top>"
 if Node.email <> "" then
  response.Write "<a title='"&Node.email&"' href='SendMail.asp?email="&Node.email&"' target='_blank'><img src='image/xiao.jpg' border=0></a> "
 else
  response.Write "&nbsp;"
 end if
 response.Write "</td>"
 response.Write "<td width=10>&nbsp;</td>"
 response.Write "</tr>"
 response.Write "<tr>"
 response.Write "<td width=10>&nbsp;</td>"
 response.Write "<td  colspan='2'>"
 '内容
 response.write "<span style='line-height: 150%'>"&replace(Node.content,keyword,"<font color=#FF0000>"&keyword&"</font>")&"</span>"
 '================================
 if Node.address <> "" or Node.phone <> "" then
  response.Write "<br>&nbsp;&nbsp;&nbsp;&nbsp;"
 end if
 if Node.address <> "" then
  response.Write "<font color=#000000>联系地址:</font>"&Node.address
 end if
 if Node.phone <> "" then
  response.Write " <font color=#000000>联系电话:</font>"&Node.phone
 end if
 
 '================================
 response.Write "</td>"
 response.Write "<td width='100' valign=top>"
 response.Write "</td>"
 response.Write "<td width=10>&nbsp;</td>"
 response.Write "</tr>"
 
 response.Write "<tr><td colspan='5' height=10 style='border-bottom:#CCCCCC 1px dotted'>&nbsp;</td></tr>"
 response.Write "<tr><td colspan='5' height=10>&nbsp;</td></tr>"
 response.Write "</table>"
End Function
%>

这个文件就是节点类,和一些操作函数

在 search.asp 里要用到。search.asp 主要解决 生成树 的问题。

文件名:search.asp

部分内容:


'''''''''''''''''''''''''''''''''''''''''''''''''''''
'排序
set id=rs("id")
set title=rs("title")
set content=rs("content")
set url=rs("url")
set oicq=rs("oicq")
set email=rs("email")
set sort_path=rs("sort_path")
set tim = rs("time")
set sequence = rs("sequence")
set address = rs("address")
set phone = rs("phone")
set keywords = rs("keyword")
dim parent, lcur, rcur
n = 0
do until rs.eof
 '生成节点
 set hi = new TreeNode
 CAll hi.Init(id, title, content, url, oicq, email, sort_path, tim, sequence, address, phone)
 if n = 0 then
  set parent = hi
  set lcur = hi
  set rcur = hi
 else
  '分割关键词
  array_keyword = split(keywords, ",")
  ispipei = false
  for i=0 to ubound(array_keyword)
   if array_keyword(i) = keyword then
    ispipei = true
   end if
  next
  '''是否匹配插入树中
  if ispipei = true  then '如果完全匹配,插入左边
   set lcur.LTreeNode = hi
   set lcur = hi
  else
   set rcur.RTreeNode = hi
   set rcur = hi
  end if
 end if
n = n+1
rs.movenext
loop
'排序结束
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'输出开始
Call ShowTrees(parent)
'输出结束
''''''''''''''''''''''''''''''''''''''''''''''''''''

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值