现在的位置: 首页 > 综合 > 正文

单链表逆输出

2013年10月05日 ⁄ 综合 ⁄ 共 195字 ⁄ 字号 评论关闭

实际上递归实现单链表逆输出不一定优于辅助堆栈或辅助数组,只是可读性更强

代码:

typedef struct node{
	int data;
	struct node * next;
} Node;

void print(Node * p){
	assert(p != NULL);

	if(p->next != NULL)  //递归,先输出后继结点
		print(p->next);
	printf("%d ", p->data);  //再输出当前结点
}

抱歉!评论已关闭.