找回密码
 点一下

疯人¢衰人

https://bbs.islga.org/?4487

数组变量系统

已有 305 次阅读2009-5-16 18:47

globals
    location                udg_UseLocat              = null
    //当前使用Location                                        
    integer                udg_UseAddress            = 0
    //正在使用的Handle值
    integer                udg_Digit                  = 10
    //位长,也就是一个支链的长度
endglobals
//辅助函数
function Digit takes integer i returns integer
    //获得整数i的位数
    local integer TempInt = 0
    loop    
        set TempInt = TempInt + 1
        set i = i / udg_Digit
        exitwhen i == 0
    endloop
    return TempInt
endfunction
function GetDigit takes integer i,integer n returns integer
    //获得整数i的第n位的值(超过最大位数返回0)
    loop
        set n = n - 1
        exitwhen n == 0
        set i = i / udg_Digit
        if i == 0 then
            return 0
        endif
    endloop
    return i-i / udg_Digit * udg_Digit
endfunction
function FindLocationInList takes location l,integer n returns location
    //返回以l为链表头的链表的第n个节点
    local integer udg_UseAddress = 0
    local integer TempInt = 0    
    local location udg_UseLocat = null
    if GetLocationY(l) == 0 then
        set udg_UseLocat = Location(-1,0)
        call MoveLocation(l,GetLocationX(l),I2R(udg_UseAddress))
    endif
    set udg_UseAddress = R2I(GetLocationY(l))
    loop  
        exitwhen n == 0
        if GetLocationX(udg_UseLocat) == -1 then
            set l = udg_UseLocat
            set udg_UseLocat = Location(-1,0)
            call MoveLocation(l,I2R(udg_UseAddress),GetLocationY(l))
        else
            set udg_UseAddress = R2I(GetLocationX(udg_UseLocat))
        endif  
        set n = n - 1
    endloop
    set l = udg_UseLocat
    set udg_UseLocat = null
    return l
endfunction
function FindLocationInArray takes location l,integer n returns location
    //插入数据r到数组变量l序号为n的位置
    local integer udg_UseAddress = 0
    local integer TempIntA = Digit(n)
    local integer TempIntB = R2I(GetLocationY(l))
    local real TempRea = 0        
    local location udg_UseLocat = null
    if TempIntA > TempIntB then
        set TempRea = GetLocationX(l)
        loop
            exitwhen TempIntA - TempIntB == 0
            set TempIntB = TempIntB + 1
            set udg_UseLocat = Location(-1,TempRea)
            set TempRea = I2R(udg_UseAddress)
        endloop
        call MoveLocation(l,TempRea,I2R(TempIntA))
    endif    
    set TempIntA = R2I(GetLocationY(l))
    set udg_UseAddress = R2I(GetLocationX(l))
    set l = udg_UseLocat
    loop
        exitwhen TempIntA == 0
        set l = FindLocationInList(l,GetDigit(n,TempIntA))  
        set TempIntA = TempIntA - 1
    endloop
    set udg_UseLocat = null
    return l
endfunction
function DeleteListLocation takes location l returns nothing
    //删除链表      
    local location udg_UseLocat = null
    local integer udg_UseAddress = R2I(GetLocationY(l))
    loop          
        exitwhen udg_UseAddress == -1
        set l =  udg_UseLocat
        set udg_UseAddress = R2I(GetLocationX(l))
        call RemoveLocation(l)
    endloop
    return  
endfunction
function DeleteArrayLocation takes integer n,location l returns nothing
    //处理带支路的链表
    local location udg_UseLocat = null  
    local integer udg_UseAddress = R2I(GetLocationY(l))
    loop
        exitwhen udg_UseAddress == -1
        if GetLocationY(udg_UseLocat) != 0 then
            if n == 1 then
                call DeleteListLocation(udg_UseLocat)
            else  
                set n = n - 1  
                call DeleteArrayLocation(n,udg_UseLocat)
            endif
        endif
        set udg_UseAddress = R2I(GetLocationX(l))
    endloop
    call DeleteListLocation(l)
    set udg_UseLocat = null
    return
endfunction
//实际应用函数
function CreateArray takes nothing returns location  
    //创建数组变量    
    local integer udg_UseAddress = 0
    local location udg_UseLocat = Location(-1,0)
    local real TempRea = I2R(udg_UseAddress)
    set udg_UseLocat = null
    return Location(TempRea,1)
endfunction
function InputDataInArray takes location l,integer n,real r returns nothing
    // 输入数据
    set l = FindLocationInArray(l,n)
    call MoveLocation(l,GetLocationX(l),r)
    return
endfunction
function OutputDataInArray takes location l,integer n returns real
    // 输出数据
    return GetLocationY(FindLocationInArray(l,n))
endfunction
function DeleteArray takes location l returns nothing  
    // 清除数组  
    call DeleteArrayLocation(R2I(GetLocationY(l)),l)
    call RemoveLocation(l)
endfunction

路过

鸡蛋

鲜花

握手

雷人

发表评论 评论 (1 个评论)

回复 ainikexie 2011-2-19 21:29
[s:299][s:304]你很久没有写博了阿 [url=http://nike.ai39.cn/catalog.asp?tags=%E8%80%90%E5%85%8B%E9%9E%8B%E4%B8%AD%E5%9B%BD%E5%AE%98%E6%96%B9%E7%BD%91]耐克鞋中国官方网 [/url] [s:246] [s:52] [s:183]

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 点一下

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-5-5 08:16 , Processed in 0.391923 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部