This document outlines the helper functions available for visualizing various data structures.
Creates a linked list from an array of values.
Parameters:
arr
: Array of numbers or strings
Returns:
- A linked list where each node contains a value from the input array
- Returns
null
/None
if the input array is empty
Example:
Converts a linked list back to an array.
Parameters:
head
: The head node of the linked list
Returns:
- Array containing all values from the linked list in order
Example:
Creates a queue from either a string or an array.
Parameters:
input
: Either a string or an array of numbers/strings
Returns:
- A queue containing all elements from the input
- Python: Returns
None
if input is empty
Example:
Converts a queue to an array while preserving the original queue.
Parameters:
queue
: A Queue instance
Returns:
- Array containing all elements in the queue in FIFO order
Example:
Creates a binary tree from an array using level-order traversal (breadth-first).
Parameters:
arr
: Array of numbers/strings/null values representing the tree in level-order- Use
null
/None
to represent empty nodes
Returns:
- Root node of the created binary tree
- Returns
null
/None
if input array is empty or starts with null
Example:
Converts a binary tree to an array using level-order traversal.
Parameters:
root
: Root node of the binary tree
Returns:
- Array representing the tree in level-order
- Empty nodes are represented as
null
/None
- Trailing nulls are removed
Example:
Creates a stack from an array, where the last element becomes the top of the stack.
Parameters:
arr
: Array of numbers or strings
Returns:
- A stack containing elements from the array
Example:
Converts a stack to an array while preserving the original stack.
Parameters:
stack
: A Stack instance
Returns:
- Array containing elements in LIFO order (top of stack first)
Example: