.
.從任一結點出發都可訪問到鏈表中每一個元素
.u=p>next; p>next=u>next; free(u);
.L>next>next==L .p>next!=null
.L>next==L && L>prior==L
.s>next=p>next;p>next=s;
.() IF pa=NIL THEN return(true);
() pb<>NIL AND pa^data>=pb^data
() return(inclusion(papb));
() pb:=pb^next;
() return(false);
非遞歸算法
()pre:=pb;
() pa<>NIL AND pb<>NIL AND pb^data>=pa^data
()pa:=pa^next; pb:=pb>next;
()pb:=pre^next;pre:=pb;pa:=pa^next;
()IF pa=NIL THEN return(true) ELSE return(false);
[注]本題是在鏈表上求模式匹配問題非遞歸算法中用指針pre指向主串中開始結點(初始時為第一元素結點)若主串與子串對應數據相等兩串工作指針pa和pb後移;否則主串工作指針從pre的下一結點開始(這時pre又指向新的開始結點)子串工作指針從子串第一元素開始比較一直繼續到循環條件失敗若pa為空則匹配成功返回true否則返回false
.A.VAR head:ptr B new(p) C p^data:=k D q^next:=p E q:=p(帶頭結點)
.() new(h);∥生成頭結點以便於操作
() r^next:=p;
() r^next:=q;
() IF (q=NIL) THEN r^next:=p;
.A: r^link^data<>max AND q^link^data<>max
B: r:=r^link
C: q^link
D: q^link
E: r^link
F: r^link
G: r:=s(或r:= r^link)
H: r:=r^link
I: q^link:=s^link
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/23368.html