()本題要求倒排循環鏈表與上面倒排單鏈表處理不同之處有二一是初始化成循環鏈表而不是空鏈表;二是判斷鏈表尾不用空指針而用是否是鏈表頭指針算法中語句片段如下
p=la>next;∥p為工作指針
la>next=la;∥初始化成空循環鏈表
while(p!=la)∥當p=la時循環結束
{r=p>next;∥暫存p的後繼結點
p>next=la>next;∥逆置
la>next=p; p=r;
}
()不帶頭結點的單鏈表逆置比較復雜解決方法可以給加上頭結點
la=(LinkedList)malloc(sizeof(node));
la>next=L;
之後進行如上面()那樣的逆置最後再刪去頭結點
L=la>next;∥L是不帶頭結點的鏈表的指針
free(la);∥釋放頭結點
若不增加頭結點可用如下語句片段
p=L>next;∥p為工作指針
L>next=null;∥第一結點成為尾結點
while(p!=null)
{r=p>next;
p>next=L;∥將p結點插到L結點前面
L=p;∥L指向新的鏈表第一元素結點
p=r;
}
()同()只是敘述有異
()同()差別僅在於敘述不同
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/23325.html