Singly Linked Lists with TypeScript

Singly Linked Lists with TypeScript

We will be looking at singly linked lists with TypeScript in this post. Linked Lists are a commonly occuring data structure, and this blog will help you understand how to implement one using Typescript.

Data structures lie at the heart of programming, and often come in handy when you least expect them to. And even when they don’t, you do definitely need them to crack a lot of interviews.

Image for post

Linked Lists are a commonly occuring data structure, and this blog will help you understand how to implement one using typescript.

We will be looking at singly linked lists in this post.

To keep things interesting, we will use a pretty cool use case. Gaming is one of my favourite hobbies, and so we’ll use linked lists to calculate the damage done by a character at the end of an attack sequence.

How Linked Lists fit into our use case

If we imagine a character attacking another character, then in the best case this particular character should be able to land an indefinite number of hits until the HP of the victim is exhausted.

So we have an uncertain length of attack input that can be received already.

Afterwards, we will need to calculate the entire attack chain for reflecting the aggregate damage, and apply special buffs such as move multipliers if necessary.

Linked lists can come in handy here, as we can use them to accommodate an uncertain amount of nodes that are being inserted.

And these nodes do not have to be contiguous, unlike arrays, so we can distribute them across memory space and link them using pointers instead.

This also helps eliminate the problem of shifting nodes up and down using the same contiguous memory block, or wasting memory as arrays often allocate an upper limit for storing elements. Which might never be reached.

A disadvantage however, is accessing particular nodes to inspect their stats. This could have been faster in arrays, but in our case we only care about the aggregate damage done.

We can recalculate the total damage done each time a node is added or removed.

So, let’s get started.

typescript javascript web-development programming

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

TypeScript Tutorial For JavaScript Developers - TypeScript Basics

TypeScript Tutorial For JavaScript Developers - TypeScript Basics. I will show you guys 4 example of JavaScript code, and how to convert it to TypeScript. This is a typescript beginners tutorial.

What is TypeScript? Why TypeScript? and Why Not TypeScript?

TypeScript extends JavaScript by adding Types. There are many great reasons to switch to TypeScript. Especially if your team uses JavaScript. There are some reasons to not use TypeScript as there are with any language or framework.

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

What, Why, and How of Typescript for JavaScript Developers

This guide gives an introductory but comprehensive guide to Typescript any Javascript developer would need to get started with it. Learn the what, why and how of Typescript, an introduction for beginners.