My First Data Structure: Linked Lists

I’m sure Ryan is adding LinkedLists to his list!
LinkedList diagram
{ val: 2, next: { val: 17, next: { val: 23, next: null } } }
class LinkedList {  constructor(val) {
this.head = {
value: val,
next: null
}
this.tail = this.head
this.length = 1
}
}
append(val) {
let newNode = {
value: val,
next: null
}
}
append(val) {
let newNode = {
value: val,
next: null
}

this.tail.next = newNode
this.tail = newNode
this.length++
}
prepend(val) {
let newNode = {
value: val,
next: this.head
}
this.head = newNode
this.length++
}
Only if you’re list starts with my love of linked lists!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Resolvers: Angular’s one-click data delivery

An elegant angular architecture

Make NPM your build tool

Type Safety Galore! Apollo Tooling for your GraphQL Powered App

How to Set Up Google OAuth in React with React-Google-Login

How to create true cross-browser extensions?

JavaScript Project and Phase 4 with Flatiron School

How to Add Dark Mode to Your Next.js Project Using Tailwind CSS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
HopeGiometti

HopeGiometti

More from Medium

Utilizing StackOverflow to Code Efficiently

Top 4 Jest Tricks to Put On Your Cheatsheet

The First Project

Connection between C# and MYSQL