Linked List Visualization
How Linked List Works
A Linked List is a linear data structure where elements are stored in nodes. Each node contains a data field and a reference (or link) to the next node in the sequence. Unlike arrays, linked list elements are not stored at contiguous memory locations. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration.
class Node:
value
next
class LinkedList:
head
function append(value):
newNode = new Node(value)
if head is null:
head = newNode
else:
current = head
while current.next is not null:
current = current.next
current.next = newNode
visualize()
function prepend(value):
newNode = new Node(value)
newNode.next = head
head = newNode
visualize()
function delete(value):
if head is null:
return
if head.value == value:
head = head.next
visualize()
return
current = head
while current.next is not null:
if current.next.value == value:
current.next = current.next.next
visualize()
return
current = current.next