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/nullptrif 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
- Returns
None/nullptrif 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/nullptrto represent empty nodes
Returns:
- Root node of the created binary tree
- Returns
null/None/nullptrif 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/T() - 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:
Parameters:
data: Graph data in adjacency list format. See examples for details.directedGraph: Whether the graph is directed. Defaults to true/True.
Return Value:
- Returns data similar to the input, which can be treated as the data itself.
Examples: