开发者

The last node in a linked list

I am implementing a linked list in Java. Is it possible to create create and use an instance variable "lastNode" in the list collection class? Or I should always access the last node thr开发者_运维百科ough following the links of the nodes starting form the first node?


Creating a lastNode (or tail) reference is completely viable and in fact very useful for certain applications. Just remember, you need to update lastNode whenever another operation such as Add() or Remove() might affect it.

You may also wish to look up the concept of doubly-linked lists if you're not familiar with them already. Depending on your applications, they can be very effective.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜