#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node * next;
}Node,*ListNode;
/*
测试用例:
1 空链表
2 只有一个结点
*/
//能否改变原来的数据结构
void printReversingly(Node *pHead)
{
std::stack<Node> nodes;
Node *pNode = pHead;
while(pNode)
{
nodes.push(pNode);
pNode = pNode->next;
}
while(!nodes.empty())
{
pNode = nodes.top();
printf("%d\t",pNode->data);
nodes.pop();
}
}
联想:
1 如果可以改变链表的数据结构呢?
2 逆向创建另一链表,然后输出.