![JAR search and dependency download from the Maven repository](/logo.png)
com.github.andyshao.data.structure.BitreePrinter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.data.structure;
import com.github.andyshao.data.structure.Bitree.BitreeNode;
import com.github.andyshao.lang.Convert;
/**
*
* Title:
* Descript:
* Copyright: Copryright(c) Nov 9, 2018
* Encoding:UNIX UTF-8
* @author Andy.Shao
*
*/
public final class BitreePrinter {
private static final String nonPad = " ";
/**
* Print {@link Bitree}
* @param tree {@link Bitree}
* @param convert the data convert
* @return the printed {@link StringBuilder}
* @param data type
*/
public static final StringBuilder printForGraph(Bitree tree, Convert convert){
BitreeNode root = tree.root();
return printForGraph(root , convert);
}
/**
* Print the {@link Bitree}
* @param treeNode {@link BitreeNode}
* @param convert the data convert
* @return the printed {@link StringBuilder}
* @param data type
*/
public static final StringBuilder printForGraph(BitreeNode treeNode, Convert convert) {
StringBuilder ret = new StringBuilder();
printForGraph(treeNode , convert , 0, ret);
return ret;
}
/**
* Print the {@link Bitree}
* @param treeNode {@link BitreeNode}
* @param convert the data convert
* @param depth the depth of the {@link Bitree}
* @param sb {@link StringBuilder}
* @param data type
*/
public static final void printForGraph(BitreeNode treeNode, Convert convert, int depth,
StringBuilder sb) {
if(treeNode == null) return;
String tabs = calculateTab(depth);
sb.append("\n").append(tabs).append("[");
sb.append(convert.convert(treeNode.data()));
printForGraph(treeNode.left(), convert, depth + 1, sb);
printForGraph(treeNode.right(), convert, depth + 1, sb);
sb.append(tabs).append("]\n");
}
static final String calculateTab(int depth) {
String tabs = null;
StringBuilder tmp = new StringBuilder();
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy