Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade For Teachers Spaces Get Certified Upgrade For Teachers Spaces
   ❮   
     ❯   

DSALinked Lists

ALinked List is, as the word implies, a list where the nodes are linked together. Each node contains data and a pointer. The way they are linked together is that each node points to where in the memory the next node is placed.

Linked Lists

A linked list consists of nodes with some sort of data, and a pointer, or link, to the next node.

A singly linked list.

A big benefit with using linked lists is that nodes are stored wherever there is free space in memory, the nodes do not have to be stored contiguously right after each other like elements are stored in arrays. Another nice thing with linked lists is that when adding or removing nodes, the rest of the nodes in the list do not have to be shifted.


Linked Lists vs Arrays

The easiest way to understand linked lists is perhaps by comparing linked lists with arrays.

Linked lists consist of nodes, and is a linear data structure we make ourselves, unlike arrays which is an existing data structure in the programming language that we can use.

Nodes in a linked list store links to other nodes, but array elements do not need to store links to other elements.

Note:How linked lists and arrays are stored in memory will be explained in more detail onthe next page.

The table below compares linked lists with arrays to give a better understanding of what linked lists are.

ArraysLinked Lists
An existing data structure in the programming languageYesNo
Fixed size in memoryYesNo
Elements, or nodes, are stored right after each other in memory (contiguously)YesNo
Memory usage is low
(each node only contains data, no links to other nodes)
YesNo
Elements, or nodes, can be accessed directly (random access)YesNo
Elements, or nodes, can be inserted or deleted in constant time, no shifting operations in memory needed.NoYes

To explain these differences in more detail, the next page will focus on how linked lists and arrays are stored in memory.


DSA Exercises

Test Yourself With Exercises

Exercise:

What is a node in a Linked List?

Each node in a Linked List contains, and a to where the next node is placed in memory.

Start the Exercise




×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookies andprivacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.


[8]ページ先頭

©2009-2025 Movatter.jp