Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Windows Tipps & SecurityNighthawk M7 Pro im Test: Flexibler, aber teurer 5G-Router(21.09.2026 um 10:30 Uhr)
Sichere ProgrammierungNeue Gmail-Funktion: So sparst du jetzt Zeit bei Einmalcodes(21.09.2026 um 10:00 Uhr)
Sichere ProgrammierungYour GIF exporter is fine — the container is the problem(21.09.2026 um 10:01 Uhr)
Sichere ProgrammierungCSS, Motion, or GSAP? I Choose by Who Owns the Animation(21.09.2026 um 10:12 Uhr)
Windows Tipps & SecurityNighthawk M7 Pro im Test: Flexibler, aber teurer 5G-Router(21.09.2026 um 10:30 Uhr)
Sichere ProgrammierungNeue Gmail-Funktion: So sparst du jetzt Zeit bei Einmalcodes(21.09.2026 um 10:00 Uhr)
Sichere ProgrammierungYour GIF exporter is fine — the container is the problem(21.09.2026 um 10:01 Uhr)
Sichere ProgrammierungCSS, Motion, or GSAP? I Choose by Who Owns the Animation(21.09.2026 um 10:12 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Doubly Linked Lists

In the last blog post we saw the implementation of Singly Linked List. Now in this post, we'll have detailed a look at his brother the Doubly Linked List. Understanding Doubly Linked Lists Just like singly linked lists, a…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

In the last blog post we saw the implementation of Singly Linked List. Now in this post, we'll have detailed a look at his brother the Doubly Linked List.









Understanding Doubly Linked Lists



Just like singly linked lists, a doubly linked list is a data structure that consists of a collection of nodes. Each node, in this case, is a separate object, but what makes it unique is that each node is linked not only to the next but also to the previous node. This two-way linkage allows for more efficient traversal in both directions.



Doubly Linked List



In contrast to the singly linked list, which only points to the next element, a doubly linked list has two pointers in each node, one pointing to the next element and one pointing to the previous element.






Adding a Node



Adding a node in a doubly linked list is a bit more intricate than in a singly linked list. Suppose we have a node cur that we want to insert between the prev node and the next node. To achieve this, we must perform the following steps:




  • Set the reference field of the prev node to point to the cur node.

  • Set the reference field of the cur node to point to the next node.

  • Adjust the reference field of the next node to also point back to the cur node, completing the two-way linkage.



The insertion process in a doubly linked list still maintains its efficiency, and you can insert a new node in O(1) time complexity when you have references to the prev and next nodes.






Deleting a Node



Deleting a node in a doubly linked list, much like insertion, requires a bit more work due to the two-way linkage. Let's consider a node cur that we want to delete:




  • Find the cur node's previous node prev and next node next first.

  • Adjust the reference field of the prev node to point to the next node, breaking the linkage from the cur node.

  • Adjust the reference field of the next node to point back to the prev node.



In a doubly linked list, finding the next node using the reference field is simple. However, finding the previous node prev is equally efficient since we can traverse the list in both directions. The time complexity for deleting a node remains O(1).






Implementation with Python



Now, let's dive into the implementation of a doubly linked list in Python:




# ListNode class represents a node in the doubly linked list.
class ListNode:
def __init__(self, val):
self.val = val # Value of the current node
self.prev = None # Reference to the previous node
self.next = None # Reference to the next node

# MyLinkedList class implements the doubly linked list with the specified methods.
class MyLinkedList:
def __init__(self):
self.head = None # Reference to the head node (the first node)
self.tail = None # Reference to the tail node (the last node)
self.size = 0 # Number of nodes in the linked list

# Get the value of the node at the specified index in the linked list.
def get(self, index):
if index < 0 or index >= self.size:
return -1 # Return -1 for an invalid index

current = self.head
for _ in range(index):
current = current.next

return current.val

# Add a new node with the given value to the head of the linked list.
def addAtHead(self, val):
new_node = ListNode(val)
if self.size == 0:
self.head = self.tail = new_node
else:
new_node.next = self.head
self.head.prev = new_node
self.head = new_node
self.size += 1

# Append a new node with the given value to the tail of the linked list.
def addAtTail(self, val):
new_node = ListNode(val)
if self.size == 0:
self.head = self.tail = new_node
else:
new_node.prev = self.tail
self.tail.next = new_node
self.tail = new_node
self.size += 1

# Add a new node with the given value before the node at the specified index.
def addAtIndex(self, index, val):
if index < 0 or index > self.size:
return # Do nothing for an invalid index

if index == 0:
self.addAtHead(val)
elif index == self.size:
self.addAtTail(val)
else:
new_node = ListNode(val)
current = self.head
for _ in range(index - 1):
current = current.next

new_node.prev = current
new_node.next = current.next
current.next.prev = new_node
current.next = new_node
self.size += 1

# Delete the node at the specified index in the linked list.
def deleteAtIndex(self, index):
if index < 0 or index >= self.size:
return # Do nothing for an invalid index

if self.size == 1:
self.head = self.tail = None
elif index == 0:
self.head = self.head.next
self.head.prev = None
elif index == self.size - 1:
self.tail = self.tail.prev
self.tail.next = None
else:
current = self.head
for _ in range(index):
current = current.next
current.prev.next = current.next
current.next.prev = current.prev

self.size -= 1






Now that's about Doubly Linked Lists. See you in the next one. Until then, Sayonara!

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Doubly Linked Lists

Thematisch verwandte Begriffe: Doubly, Linked, Lists · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94030 | A security vulnerability has been detected in SerenityOS up to 3d83e4509…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick