ASP写的链表Class,不太实用,就当练习写Class了。

    技术2022-05-11  137

    今天为了保存一组数量不定的对象集,想起了以前写的链表操作类,试着写了个小的链表操作类。谁知一发不可收拾,模仿着rs对象的几个方法写了一个链表操作类。作用嘛,大至是用于那些多个属性类的小集合。没有固态数组的上限。没有Dic的Item惟一性。至于动态数组...好象都差不多..哈,没对比出有什么不同的。或许动态数组更为节约资源吧,用哪个就个人喜好了。 '/// '// '// public sub Load(byval A_objList) '//  加载链表A_objList '//   链表节点属性: '//    public value  ->节点值,可为对象、数字或字符串 '//    public nextNode  ->下一个结节对象 '// '// public sub Addnew() '//  添加新节点,在添加前必须运行该指令才是确认为添加。 '// '// public sub Update() '//  保存添加或修改设置。 '// '// public sub Delete() '//  删除当前节点。 '// '// public sub MovePrevious() '//  将当前节点移动到上一个节点。链表只能单向移动,所以向上移动操作最好不要常用。 '// '// public sub movenext() '//  将当前节点移动到下一个节点[链表遍历是从最底到最顶]。 '// '// public sub MoveFirst() '//  将当前节点移动到开始位置。bof=true '// '// public sub MoveLast() '//  将当前节点移动到结束位置。eof=true '// '// public sub Move(byval A_objBlip) '//  将当前节点移动到之匹配的位置 '//   当A_objBlip为数字时则为移动到第几个节点(第一个节点为0), '//    但A_objBlip大于节点总数时,当前节点定位在最后一个节点。 '//   当A_objBlip为非数字型则是移动到与node.value内容匹配的第一个节点上。 '// '// public property get Count '//  返回节点个数 '// '// public property get nValue '//  返回节点值。 '// '// public property let nValue(byval A_strValue) '//  设置节点值[非object值]。 '// '// public property set nValue(byval A_objValue) '//  设置节点值[object值]。 '// '// public property get bof '//  当前节点在结束位置返回true '// '// public property get eof '//  当前节点在结束位置时返回true '// '// public property get list '//  返回当前操作的链表 '// '///

    class listNode '链表节点 public Value public nextNodeend classclass modelList '链表操作类 private c_blnEof  '节点到最后时为true,默认为false private c_blnBof  '节点到开始时为true,默认为false private c_objList  '链表对象 private c_objNownode '当前节点对象 private c_strWd   '当前操作 private c_objValue  '延用C#的规则,Object可以代替任意数据类型

     private sub Class_Initialize()  c_strWd="update"  '默认为修改操作  set c_objList=nothing '初始化链表  c_blnBof=true  c_blnEof=false end sub

     private Sub Class_Terminate()  set c_objList=nothing end sub

     public sub Load(byval A_objList) '加载链表  set c_objList=A_objList  call MoveFirst() '设置当前节点在开始位置 end sub

     public sub Addnew()  '添加新节点  c_strWd="addnew"  set c_objNownode=new listNode'声明新节点  if isobject(c_objValue) then   set c_objValue=nothing  else   c_objValue=""  end if end sub

     public sub Update()  '保存添加或修改设置。  dim MM_objList  dim MM_strNumber  if c_strWd="addnew" then  '将节点添加到链表内   if isobject(c_objValue) then    set c_objNownode.value=c_objValue   else    c_objNownode.value=c_objValue   end if   set c_objNownode.nextNode=c_objList '记录好链接点   set c_objList=c_objNownode    '记录添加结果  else   set MM_objList=c_objList   MM_strNumber=0   do while not MM_objList.nextNode is nothing '到结束端    if MM_objList is c_objNownode then      exit do    end if    set MM_objList=MM_objList.nextNode    MM_strNumber=MM_strNumber+1   loop   if isobject(c_objValue) then    execute("set c_objList" & replace(string(MM_strNumber,"0"),"0",".nextNode") & ".value=c_objValue")   else    execute("c_objList" & replace(string(MM_strNumber,"0"),"0",".nextNode") & ".value=c_objValue")   end if  end if end sub

     public sub Delete()  '删除当前节点。  dim MM_objList  dim MM_strNumber  set MM_objList=c_objList  MM_strNumber=0  do while not MM_objList.nextNode is nothing '到结束端   if MM_objList is c_objNownode then     exit do   end if   set MM_objList=MM_objList.nextNode   MM_strNumber=MM_strNumber+1  loop  if c_objNownode.nextNode is nothing then   execute("set c_objList" & replace(string((MM_strNumber-1),"0"),"0",".nextNode") & "=nothing")  else   execute("set c_objList" & replace(string((MM_strNumber),"0"),"0",".nextNode") & "=c_objList" & replace(string((MM_strNumber+1),"0"),"0",".nextNode"))  end if end sub

     public sub MovePrevious()'将当前节点移动到上一个节点  dim MM_objNode,MM_blnDo  if not c_blnBof then   set MM_objNode=c_objList   MM_blnDo=true   do while not MM_objNode.nextNode is nothing '到结束端    if MM_objNode.nextNode is c_objNownode then     set c_objNownode=MM_objNode     exit do    end if    set MM_objNode=MM_objNode.nextNode   loop  end if  set MM_objNode=nothing  c_blnEof=c_objNownode.nextNode is nothing  if isobject(c_objNownode.value) then   set c_objValue=c_objNownode.value  else   c_objValue=c_objNownode.value  end if end sub

     public sub MoveNext()'将当前节点移动到下一个节点  if c_objNownode.nextNode is nothing then  '到顶点啦。   c_blnEof=true  else   set c_objNownode=c_objNownode.nextNode   c_blnBof=false   if isobject(c_objNownode.value) then    set c_objValue=c_objNownode.value   else    c_objValue=c_objNownode.value   end if  end if end sub

     public sub MoveFirst()'将当前节点移动到开始位置  set c_objNownode=c_objList  if isobject(c_objNownode.value) then   set c_objValue=c_objNownode.value  else   c_objValue=c_objNownode.value  end if  c_blnEof=false end sub

     public sub MoveLast()'将当前节点移动到结束位置  set c_objNownode=c_objList  do while not c_objNownode.nextNode is nothing '当下一个节点为nothing时,当前节点为结束端   set c_objNownode=c_objNownode.nextNode  '往结束端移动到。  loop  if isobject(c_objNownode.value) then   set c_objValue=c_objNownode.value  else   c_objValue=c_objNownode.value  end if end sub

     '将当前节点移动到之匹配的位置 ' 当A_objBlip为数字时则为移动到第几个节点,但A_objBlip大于节点总数时,当前节点定位在最后一个节点 ' 当A_objBlip为非数字型则是移动到node.value=A_objBlip的第一个节点 public sub Move(byval A_objBlip)  dim MM_intCount  set c_objNownode=c_objList  MM_intCount=0  do   MM_intCount=MM_intCount+1   if isobject(A_objBlip) then'对象    if c_objNownode.value is A_objBlip then      exit do    end if   elseif isNumeric(A_objBlip) and lcase(typename(A_objBlip))<>"string" then'数字    if MM_intCount=A_objBlip then      exit do    end if   else'字符    if c_objNownode.value=A_objBlip then      exit do    end if   end if   set c_objNownode=c_objNownode.nextNode  '往结束端移动到。  loop while not c_objNownode.nextNode is nothing '当下一个节点为nothing时,当前节点为结束端  if isobject(c_objNownode.value) then   set c_objValue=c_objNownode.value  else   c_objValue=c_objNownode.value  end if end sub

     public property get Count '返回节点数  dim MM_intCount  dim MM_objNode  set MM_objNode=c_objList  MM_intCount=0  do while not MM_objNode is nothing   MM_intCount=MM_intCount+1   set MM_objNode=MM_objNode.nextNode  loop  Count=MM_intCount end property

     '/----------设置或返回节点操作--------/ public Default property get nValue '返回节点值  if isobject(c_objValue) then   set nValue=c_objValue  else   nValue=c_objValue  end if end property

     public property let nValue(byval A_strValue) '设置节点值  c_objValue=A_strValue end property

     public property set nValue(byval A_objValue) '设置节点值  set c_objValue=A_objValue end property '/----------设置或返回节点操作--------/

     public property get eof '当前节点在结束位置时返回true  eof=c_blnEof end property

     public property get bof '当前节点在开始位置时返回true  bof=c_blnBof end property

     public property get list'返回当前操作的链表  set list=c_objList end property

    end class


    最新回复(0)