题目描述
输入一个链表,反转链表后,输出链表的所有元素。
答案
function ReverseList($pHead)
{
if ($pHead == null) return null;
$list = null;
while ($pHead != null) {
$tem = $pHead -> next;
$pHead -> next = $list;
$list = $pHead;
$pHead = $tem;
}
return $list;
}