电竞比分网-中国电竞赛事及体育赛事平台

分享

遍歷算法在VFP中的簡單應(yīng)用

 Alkaid2015 2015-09-19
*--遍歷算法是遞歸算法的一個(gè)具體應(yīng)用實(shí)例,在程式設(shè)計(jì)中也是比較常用的算法之一


*這里介紹幾個(gè)常用的應(yīng)用實(shí)例來簡單接觸下遍歷算法的基礎(chǔ)應(yīng)用:


*--1、遍歷文件
dqml='C:' &&需掃描的盤符
Use
Create Cursor
mylsdbf (wjmc c(120),wjcd N(10),wjrq d,wjshj c(10),wjsx c(6))
xGS=1
xCD=0
Append Blank
Replace
wjmc With
dqml
Do While !Eof
()
    nRecn=
Recno
()
    dqml=
Alltrim
(wjmc)+'/'
    x=
Adir
(Mysz,(dqml+'*.*'),'rashd')
   
If
x<>0
       
For I=3 To
x
            Mysz(I,1)=dqml+Mysz(I,1)
            xGS=xGS+1
            xCD=xCD+Mysz(I,2)
       
Endfor
        Append From Array
Mysz For Alltrim(wjmc)<>'.' And Alltrim
(wjmc)<>'..' And 'D'$wjsx
   
Endif
    Go
nRecn
   
Skip
Enddo
Browse
Use


*--2、遍歷控件
Create Cursor
kjsl(kjname C(254))
Insert Into kjsl(kjname) Values
('thisform')
Do While !Eof
()
    nRECN=
Recno
()
    kjmc=
Alltrim
(kjname)
    =
Amembers
(aval,&kjmc,2)
   
If Type
('aval')<>'U'
       
For Each cval In aval
&&aval控件名稱數(shù)組,cval數(shù)組值
           
Insert Into kjsl(kjname) Values
(kjmc+'.'+cval)
       
Endfor
    Endif
    Release
aval
   
Go
nRECN
   
Skip
Enddo
Browse
 
*--3、遍歷TreeView 中指定節(jié)點(diǎn)及其所有子節(jié)點(diǎn)的算法
** aChild[1,3]是一個(gè)自定義表單數(shù)組屬性
Lparameters
cnode
** 將所有的子節(jié)點(diǎn)的特性都放到表單的數(shù)組屬性 aChild 中去
** 以便在要?jiǎng)h除一個(gè)節(jié)點(diǎn)的時(shí)候,刪除所有子節(jié)點(diǎn)的數(shù)據(jù)
Local
oCurNode, nArrayCount
nArrayCount = 1
oCurNode = cnode
&& 紀(jì)錄下第一個(gè)子節(jié)點(diǎn)的特性
This.aChild[1,1] = oCurnode.
Key
This
.aChild[1,2] = oCurnode.
Text
This
.aChild[1,3] = oCurnode.
Index
Do While
oCurNode.Children > 0
    oCurNode = oCurNode.Child
   
If oCurNode.Children > 0
&& 深入到最后一層
       
Loop
    Endif
    Do While
.T.
       
If oCurNode.Key = cNode.
Key
            Exit
        Endif
       
nArrayCount = nArrayCount + 1
       
If Isnull(oCurNode.Next)
&& 如果當(dāng)前節(jié)點(diǎn)之后沒有節(jié)點(diǎn)了
           
Dimension This.aChild[nArrayCount, 3]
&& 紀(jì)錄當(dāng)前節(jié)點(diǎn)的信息
           
This.aChild[nArrayCount, 1] = oCurNode.
Key
            This
.aChild[nArrayCount, 2] = oCurNode.
Text
            This
.aChild[nArrayCount, 3] = oCurNode.
Index
            If
!(oCurNode.Key = cnode.Key)
&& 如果當(dāng)前節(jié)點(diǎn)已經(jīng)是最高節(jié)點(diǎn)了,則立刻退出
               
oCurNode = oCurNode.Parent
&& 否則,后退一層,并重新開始循環(huán)
               
Loop
            Else
                Exit
            Endif
        Else
&& 當(dāng)前節(jié)點(diǎn)之后還有節(jié)點(diǎn),檢查后續(xù)的節(jié)點(diǎn)
           
oCurNode = oCurnode.Next
&& 將下一個(gè)節(jié)點(diǎn)設(shè)為當(dāng)前節(jié)點(diǎn)
           
Dimension This.aChild[nArrayCount,3]
&& 紀(jì)錄該節(jié)點(diǎn)的特性
           
This.aChild[nArrayCount,1] = oCurnode.
Key
            This
.aChild[nArrayCount,2] = oCurnode.
Text
            This
.aChild[nArrayCount,3] = oCurnode.
Index
            If
oCurNode.Children > 0
&& 如果該節(jié)點(diǎn)有子節(jié)點(diǎn),則退出,返回到第一個(gè)循環(huán)
               
Exit
            Endif
        Endif
        If
oCurNode.Children > 0
           
Exit
        Endif
    Enddo
    If
oCurNode.Key = cNode.
Key
        Exit
    Endif
Enddo

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請遵守用戶 評(píng)論公約

    類似文章 更多