April 2018
Beginner to intermediate
426 pages
10h 19m
English
Now that you understand what a linked list is, let's start implementing our data structure. This is the skeleton of our LinkedList class:
import { defaultEquals } from '../util';import { Node } from './models/linked-list-models'; // {1}export default class LinkedList { constructor(equalsFn = defaultEquals) { this.count = 0; // {2} this.head = undefined; // {3} this.equalsFn = equalsFn; // {4} }}
For the LinkedList data structure, we start by declaring the count property ({2}), which stores the number of elements we have in the list.
We are going to implement a method named indexOf, which will allow us to find a specific element in the linked list. To compare equality between elements of the linked list, we ...