Data Structures
These are Apas Cloud services: they run on our servers for a signed-in member. The examples below are shown already made; sign in to edit and run your own.
linkedList Apas Cloud
Creates a singly linked list, optionally filled from an array (front to back). Shows as boxes with next-pointers; pushFront/pushBack/insertAt/removeAt/remove/search/reverse/traverse animate each step.
xs (number[]) -- optional initial values
stack Apas Cloud
Creates a stack (last in, first out), optionally filled from an array (bottom to top). push/pop/peek animate; popping an empty stack shows an underflow step.
xs (number[]) -- optional initial values
queue Apas Cloud
Creates a CIRCULAR queue with a fixed capacity (1-64): front and rear indices wrap around the slot array. enqueue/dequeue/peek animate; enqueueing into a full queue shows the overflow.
capacity (number) --
xs (number[]) -- optional initial values
hashTable Apas Cloud
Creates a hash set of integer keys with h(k) = k mod m, using separate chaining (default) or linear probing ("linear", with tombstones on removal). Grows to 2m+1 buckets and rehashes when the load factor would exceed maxLoad (default 1 for chaining, 0.75 for linear).
m (number) -- bucket count, 1-97
mode (string) -- "chaining" or "linear"
maxLoad (number) -- optional load-factor limit
bst Apas Cloud
Creates a binary search tree, optionally inserting an array's values in order. insert/remove/search/traverse animate the comparisons ("4 < 5: go left"); removing a node with two children uses its in-order successor.
xs (number[]) -- optional values, inserted in order
avl Apas Cloud
Creates a self-balancing AVL tree: like bst(), but every insert/remove rebalances with single or double rotations, each shown as its own step. Nodes show their balance factor.
xs (number[]) -- optional values, inserted in order
minHeap Apas Cloud
Creates a binary min-heap (smallest value at the root), built from an array with bottom-up heapify. Drawn as a tree with its array underneath; push/pop/peek animate each compare and swap.
xs (number[]) -- optional initial values
maxHeap Apas Cloud
Creates a binary max-heap (largest value at the root) -- same as minHeap() with the order reversed.
xs (number[]) -- optional initial values
push Apas Cloud
Pushes a value onto a stack or heap (sift-up animated); on a queue it enqueues, on a tree it inserts. Returns the step-by-step animation.
ds (data structure) --
x (number) --
pop Apas Cloud
Removes and animates taking the top of a stack, the root of a heap (last element moved up, then sift-down), or the front of a queue.
peek Apas Cloud
Highlights the element pop() would take next (stack top, queue front, heap root) without removing it.
enqueue Apas Cloud
Adds a value at the rear of a circular queue, showing the rear index wrap around.
q (queue) --
x (number) --
dequeue Apas Cloud
Removes the front value of a circular queue, showing the front index advance (and wrap).
pushFront Apas Cloud
Links a new node in at the head of a linked list.
l (linked list) --
x (number) --
pushBack Apas Cloud
Appends a node at the tail of a linked list -- the walk from the head to the tail is shown step by step (a singly linked list has no tail pointer).
l (linked list) --
x (number) --
insertAt Apas Cloud
Inserts a value so it ends up at position i (0 = front) of a linked list, walking to the node before it.
l (linked list) --
i (number) -- 0-based position
x (number) --
removeAt Apas Cloud
Unlinks the node at position i (0 = front) of a linked list.
l (linked list) --
i (number) -- 0-based position
insert Apas Cloud
Inserts a value into a BST/AVL tree (compare path, then any rotations), a hash table (h(k), probing/chaining), a heap (sift-up), a linked list (at the back) or a stack/queue.
ds (data structure) --
x (number) -- an integer for a hash table
remove Apas Cloud
Removes a value from a BST/AVL tree (leaf, one-child and two-child cases), a hash table (a tombstone under linear probing) or a linked list (first match).
ds (data structure) --
x (number) --
search Apas Cloud
Searches a BST/AVL tree, hash table or linked list for a value, animating each comparison or probe until it is found or ruled out.
ds (data structure) --
x (number) --
reverse Apas Cloud
Reverses a linked list in place with the three-pointer method: the boxes stay put while each next-pointer flips, one step at a time.
traverse Apas Cloud
Walks a tree in "inorder" (default), "preorder", "postorder" or "levelorder" order -- numbering each node as it is visited and building the output list -- or walks a linked list front to back.
ds (tree or linked list) --
order (string) -- optional traversal order
toArray Apas Cloud
The structure's values as an ordinary array: list front to back, stack bottom to top, queue front to rear, tree in-order, heap in array order, hash table in bucket order.
size Apas Cloud
How many values the structure holds.
height Apas Cloud
Height of a BST/AVL tree (a single node has height 1, an empty tree 0).