题目:输入一个链表的头结点,从尾到头反过来打印出每个节点的值。
<span style="font-size:18px;">void PrintList(SListNode * &ppHead)
{
std:: stack<SListNode *> Nodes;
SListNode* cur = ppHead ;
while (cur)
{
Nodes.push(cur);
cur = cur->next;
}
while (!Nodes.empty())
{
SListNode* top = Nodes.top();
cout << top->data << " ";
Nodes.pop();
}
}</span>
<span style="font-size:18px;">
//从尾到头打印(递归打印)
void printlist(slistnode * &pphead)
{
if (pphead == null)
//cout << "null";
return;
else
{
//递归打印
printlist(pphead->next);
cout << pphead->data << " ";
}
}
</span>