Skip to content

Linked List

Sgt. Mahdi edited this page Apr 11, 2025 · 4 revisions

What's Linked List?

It's a way to store a collection of data like numbers, where each data is part of a chain. instead of being stored one after another in the memory, each item is placed in a node located at a diffrent memory address (Unlike Array it's not contiguous)
There are two types of linked list:

  1. Singly Linked List

Singly Linkedlist

  1. Doubly Linked List

Doubly Linkedlist

What's Node?

It's an object which holds data and addresses.
There are two types of nodes:

  1. Singly: this type stores two things

Data
Address of the next node

  1. Doubly: this type stores three things

Data
Address of the next node
address of the previous node

See My Custom Node Structure

Singly Node

Adding a New Data Into Linked List:

When you add new data to a linked list, you're creating a new node and linking it into the chain.

  1. Create a new Node.
  2. Set the new node’s pointer to the next node (or to null if it's going at the end)
  3. Update the previous node's pointer to link to the new node.

Adding new data into linkedlist

You can see how to code this process in My Custom Linked List Class

My Custom Doubly Linked List Class

This file you'll see how to code doubly linked list:

My Custom Linked List Class

Clone this wiki locally