![Introduction to Data Structures for Interviews](https://static.frontendmasters.com/assets/courses/2018-08-09-data-structures-interviews/thumb.webp)
Check out a free preview of the full Introduction to Data Structures for Interviews course
The "Linked List: Head, Tail & Contains" Lesson is part of the full, Introduction to Data Structures for Interviews course featured in this preview video. Here's what you'd learn in this lesson:
Bianca implements the isHead(), isTail(), and contains() methods.
Transcript from the "Linked List: Head, Tail & Contains" Lesson
[00:00:00]
>> Bianca Gandolfo: So, what else can we do? So we removed. So is head, this was easy, right? Return this.head.
>> Bianca Gandolfo: Wait, this is isTail. Return, so we have a node. So return node, if node === this.head.
>> Student: You're just checking whether it's true or not?
>> Bianca Gandolfo: Yeah, like is the node, the head, is this the tail.
[00:00:39]
So it's gonna return a boolean. Yeah. Contains, so contains is another one where you would loop through. So what we could do is. So we're gonna pass some value against. So this one we're checking for a particular value, not a node. But we would have to loop through pretty similarly So I'm gonna copy our remove tail implementation.
[00:01:04]
And so we're gonna start at the beginning. We have our value. So while current node value is not equal to our value, keep looping.
>> Bianca Gandolfo: So, and then once we exit. So, if currentNode.value === value, actually we could just return this. So if it equals, if does equal return true, if not this will return false.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops