bbs的树状结构算法

2016-01-29 18:25 38 1 收藏

bbs的树状结构算法,bbs的树状结构算法

【 tulaoshi.com - ASP 】

  数据库设计中order_value是用来排序的,具体实现是   
**注意以下的讨论是对一个主题而言,就是对一棵树而言!   
如果加一新贴那么  order_value=0   
如果跟贴查比父贴  order_value大的order_value   
如果有假设为next_value,那么新帖的   
order_value为父贴的(order_value+next_value)/2;   
如果有那么新帖的order_value为父贴的order_value+1000   
也就是说如果对A贴跟贴,如果A为末贴,A的字帖的order_value为order_value(父)+1000,   
不是末贴既找出比A大的order_value,新的order_value为两者的一半!   
排序实现: order by groupid,order_value desc   
**技巧如果想实现层次多一点可以每次加的多一点+100000,那样应该会好一点   

***不足之处:   
1:使用两个字段排序,速度有点慢   
2:使用order_value是一个浮点数,使用float估计不够,还是使用double   
3:只能实现理论上的无穷层实际上超过10层使用float有问题,使用double可能没有   
4:插入是需要查找下一个order_value

Dim ordervalue, nextvalue As Double
sql = "select gorders where gId=" & gId & " and goders " & gorders & " order by goders  "
rs1.Open sql, conn1, adOpenForwardOnly, adLockOptimistic '查询比父贴大的
                                                          order_value
If (rs1.EOF And rs1.BOF) Then
  gorders = gorders + 256
  gLayer = gLayer + 1
Else
  nextvalue = rs1("gorders")
  If (nextvalue - gorders) 1 Then
   gorders = Int((gorders + nextvalue) / 2)
   gLayer = gLayer
  Else
     'gorders,glayer跟回帖一样
End If
End If

End Sub

 

来源:https://www.tulaoshi.com/n/20160129/1505702.html

延伸阅读
标签: ASP
  /*************************************************************************/ /* */ /* procedure : up_GetForumList */ /* */ /* Description: 取得版面列表 */ /* */ /* Parameters: None */ /* */ /* Use table: forum , bbsuser */ /* */ /* Author: bigeagle@163.net */ /* */ /* Date: 2000/2/10 */ /* */ /* History: */ /* *...
标签: ASP
  /*数据结构*/ /*bbs用户表*/ if exists(select * from sysobjects where id = object_id('BBSUser')) drop table BBSUser go create table BBSUser ( id int identity primary key , UserName varchar(20) default '' not null , Password varchar(10) default '' not null , Email varchar(100) default '' not null , Homepage var...
标签: ASP
  加贴存储过程: if exists (select * from sysobjects where id = object_id("lybsave"))    drop proc lybsave CREATE PROCEDURE [lybsave] @keyid int=0,@guestname varchar(20),@guestitle varchar(100),@guestcomm text,@guestemail varchar(50)='',@emailflag bit=0,@fromip varchar(15),@recimail varc...
程序代码如下: 代码如下: // BubbleSort.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include cmath #include iostream using namespace std; #define  MAXNUM 20 templatetypename T void Swap(T& a, T& b) {     int t = a;     a = b;     b = t; } templatetypenam...
标签: ASP
  程序名称:revert.asp 程序功能:回复表单 <!-- #include file="lybcon.inc" -- <% pageno=request("pageno") keyid=request("keyid") posttype=request("type") if posttype="revert" then   set guestconn=Server.CreateObject("ADODB.connection") &n...

经验教程

792

收藏

27
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部