用递归算法实现链表操作
用递归算法实现链表操作:实现输出链表中的所有结点值
麻烦各位高手帮忙解解,在下感激不尽····
[解决办法]
#include "iostream"
using namespace std;
struct Node {
int data;
Node* pNext;
Node(int d, Node* next) : data(d), pNext(next)
{
}
};
void print_link(const Node* pNode)
{
if (!pNode)
return;
cout < <pNode->data < <" ";
print_link(pNode->pNext);
}
int main()
{
Node* pRoot = new Node(1, new Node(2, new Node(3, new Node(4, NULL))));
print_link(pRoot);
cout < <endl;
// release link
return 0;
}