读书人

用递归算法实现链表操作解决办法

发布时间: 2012-02-24 16:30:39 作者: rapoo

用递归算法实现链表操作
用递归算法实现链表操作:实现输出链表中的所有结点值
麻烦各位高手帮忙解解,在下感激不尽····


[解决办法]

C/C++ code
 
#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;
}

读书人网 >C++

热点推荐