Data Structure Visualization Helper Functions

This document outlines the helper functions available for visualizing various data structures.

Table of Contents

Linked List Functions

Create Linked List

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:

Convert Linked List to Array

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:

Queue Functions

Create Queue

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:

Convert Queue to Array

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:

Binary Tree Functions

Create Binary Tree

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:

Convert Binary Tree to Array

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:

Stack Functions

Create Stack

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:

Convert Stack to Array

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: