简体   繁体   中英

How do i implement a 2 Dimensional Linked List in java?

I'd like to know about the implementation of the 2D Linked List in java. As we all know there are head and tail pointers in linked list, but how should i code when i'm tying to code 2D linked List? The list may contain many rows and columns extending their data sets infinitely. So the same logic for head or tail reference may not work. Any ideas?

The short answer is don't. Java already implements LinkedList as you know, so just use this:

LinkedList<LinkedList<YourClassHere>> list = new LinkedList<LinkedList<<YourClassHere>>();

The slightly longer answer is it's actually pretty simple: it's just a linked list of linked lists. Therefore, if you have a singly linked list, you can just make the nodes linked lists themselves.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM