New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

format-binary-tree

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-binary-tree

Array-based binary trees to string

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Greenkeeper badge Build Status codecov npm npm

format-binary-tree

Binary trees can be stored as a linked list, but they can also be represented as an array (for example, when working with binary heaps).

I didn't see a library that formats binary trees implemented as an array, so I decided to create this very simple library.

Installation

npm install format-binary-tree
yarn add format-binary-tree

Usage

import formatBinaryTree from 'format-binary-tree';

formatBinaryTree({ values: [1, 2, 3, 4, 5, 6, 7, 8, 9] });

// • 1
//   • 3
//     • 7
//     • 6
//   • 2
//     • 5
//     • 4
//       • 9
//       • 8

API

formatBinaryTree({ values, nodeSymbol, indentationSize })

  • values is the array of values that represent the binary tree
  • nodeSymbol is the string that prefixes each node - defaults to
  • indentationSize is a number that represents the number of spaces to indent each level - defaults to 2

formatBinaryTree traverses the tree by going root, right, left. I know this isn't a "standard" traversal, but I found it easier to visualize the tree this way.

Keywords

array

FAQs

Package last updated on 09 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts