博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2.2
阅读量:2382 次
发布时间:2019-05-10

本文共 376 字,大约阅读时间需要 1 分钟。

Implement an algorithm to find the nth to last element of a singly linked list.

分析:查找链表倒数第n个元素,这在剑指offer上有相同的习题

Node* get_lastn(Node* head,int n){	if(head==NULL||n<=0) return NULL;	Node* front=head;	Node* behind=head;	while(n>1){		behind=behind->next;		if(behind==NULL) return NULL;		n--;	}	while(behind->next!=NULL){		front=front->next;		behind=behind->next;	}	return front;}

转载地址:http://ybyab.baihongyu.com/

你可能感兴趣的文章
迅雷C++试题及解答
查看>>
Linux 中断学习之小试牛刀篇
查看>>
中断之原理篇
查看>>
高内聚 低耦合
查看>>
GUI开发之DirectFB
查看>>
GTK/DirectFB两个闪烁的问题
查看>>
《Linux内核修炼之道》 之 高效学习Linux驱动开发
查看>>
编写可移植C/C++程序的要点
查看>>
DirectFB代码导读
查看>>
linux fork函数浅析
查看>>
内核启动时间优化
查看>>
基于Linux的多播编程
查看>>
网络字节序
查看>>
Linux网络命令详解
查看>>
GNU C 的 __attribute__ 机制
查看>>
atoi,atol,strtod,strtol,strtoul详解
查看>>
基于HZK16的汉字显示技术
查看>>
嵌入式web服务器对比
查看>>
select 函数使用指难
查看>>
人类的15个欲望与游戏设计
查看>>