DSAverse
Basics & Data Structures
Loading Data Structures...
Array Access
12
05
18
23
317
49
5array[0..5]indexed access
Array
Stack
Queue
Initializing Sorting Algorithms...
Sorting
Trees
Graphs
Preparing interactive visualizations...
Basics & Data Structures
Loading Data Structures...
Array Access
Array
Stack
Queue
A dynamic stack using linked nodes. No fixed capacity — the top is always the head node.
The HEAD node is always the TOP. Each node holds a value + a pointer to the next node.
Color Legend
Use Push, Pop, or Peek to begin visualization.
Create node → set next = old head → update head to new node
Store head value → move head to head.next → return stored value
Return head.value without modifying the list
In a linked list stack, where is the TOP of the stack?
class Node:
def __init__(self, value):
self.value = value
self.next = None # Reference to next node
class StackLinkedList:
def __init__(self):
self.head = None # TOP of stack
self.size = 0
def push(self, value):
new_node = Node(value)
new_node.next = self.head # Point to old top
self.head = new_node # New node is now top
self.size += 1
return value
def pop(self):
if self.head is None:
raise Exception("Stack Underflow")
value = self.head.value
self.head = self.head.next # Move top to next
self.size -= 1
return value
def peek(self):
if self.head is None:
raise Exception("Stack is Empty")
return self.head.value
def is_empty(self):
return self.head is None
def get_size(self):
return self.size