From the course: Java Algorithms

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Create a custom data structure for linked list algorithms

Create a custom data structure for linked list algorithms - Java Tutorial

From the course: 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…

Contents