()本題基本與()相同但要求無重復元素故在算法中待合並結點數據要與其前驅比較只有在與前驅數據不同時才並入鏈表其核心語句段如下
pa=L>next;pb=L>next;∥papb是兩鏈表的工作指針
pc=L;∥L作結果鏈表的頭指針
while(pa&&pb)
if(pa>data<pb>data) {u=pa;pa=pa>next;free(u);}∥刪除L表多余元素
else if (pa>data>pb>data) pb=pb>next;∥pb指針後移
else∥處理交集元素
{if(pc==L) {pc>next=pa;pc=pa;pa=pa>next;}∥處理第一個相等的元素
else if(pc>data==pa>data){ u=pa;pa=pa>next;free(u);}∥重復元素不進入L表
else{ pc>next=pa;pc=pa;pa=pa>next;}∥交集元素並入結果表
} ∥while
while(pa) {u=pa;pa=pa>next;free(u);}∥ 刪L表剩余元素
pc>next=null; ∥置結果鏈表尾
注 本算法中對L表未作釋放空間的處理
() 本題與上面()算法相同只是結果表要另辟空間
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/23357.html