课程: Java Algorithms

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Create a custom data structure for linked list algorithms

Create a custom data structure for linked list algorithms - Java教程

课程: Java Algorithms

Create a custom data structure for linked list algorithms

- [Instructor] Although there's a linked list data structure available in Java, not every algorithm you'll ever need will be built into the standard library. Instead, you may need to create your own data structure with your own algorithms to manipulate your data more effectively. In fact, we can create our own linked list in Java using classes, specifically a LinkedList class and a node class. Here we have a custom LinkedList class that has a Node attribute called head. This represents the first item or the head of the list. We also have a class called Node, which is used by the LinkedList. Each node has an int data and a reference to the next node in the list. Let's create a LinkedList from the CustomLinkedList class. We'll use the built-in constructor. Then we can create some nodes to put in the list. To put the firstNode in the list, we can set the head node equal to the firstNode. We'll access the list, .head and we'll give it the firstNode. To add the rest of the nodes, we'll…

内容