您的位置:首页 > 职场人生

程序员面试100题之三十一,从尾到头输出链表

2010-09-24 17:24 225 查看
// 100_31.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
struct Node
{
Node * next;
int value;
};

void print(Node * head)
{
if(!head)
return;
if(head->next)
{
print(head->next);
}
printf("%d ",head->value);

}

int _tmain(int argc, _TCHAR* argv[])
{
Node * n1 = new Node();
Node * n2 = new Node();
Node * n3 = new Node();

n1->next = n2;
n1->value = 1;

n2->next = n3;
n2->value = 2;

n3->next = NULL;
n3->value = 3;

print(n1);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: