Skip to main content
added 163 characters in body
Source Link
seeker
  • 125
  • 5
public class TreeNode {

     int data;
    private TreeNode left;
    private TreeNode right;
    public TreeNode getLeft() {
        return left;
    }
    public void setLeft(TreeNode left) {
        this.left = left;
    }
    public TreeNode getRight() {
        return right;
    }
    public void setRight(TreeNode right) {
        this.right = right;
    }
     
    
    public TreeNode(int data)
    {
        this.data=data;
    }
    this.setLeft(null);
   }

Call to the method

 Map<Integer,Set<Integer>> verticalStrips = new this.setRightHashMap<Integer,Set<Integer>>(null); 
verticalStrips =printStripsVertically(root,verticalStrips,0);//where root is }
the root of the 
}tree.
public class TreeNode {

     int data;
    private TreeNode left;
    private TreeNode right;
    public TreeNode getLeft() {
        return left;
    }
    public void setLeft(TreeNode left) {
        this.left = left;
    }
    public TreeNode getRight() {
        return right;
    }
    public void setRight(TreeNode right) {
        this.right = right;
    }
     
    
    public TreeNode(int data)
    {
        this.data=data;
        this.setLeft(null);
        this.setRight(null);
    }
    
}
public class TreeNode {

     int data;
    private TreeNode left;
    private TreeNode right;
    public TreeNode getLeft() {
        return left;
    }
    public void setLeft(TreeNode left) {
        this.left = left;
    }
    public TreeNode getRight() {
        return right;
    }
    public void setRight(TreeNode right) {
        this.right = right;
    }
     
    
    public TreeNode(int data)
    {
        this.data=data;
    }
    
}

Call to the method

 Map<Integer,Set<Integer>> verticalStrips = new HashMap<Integer,Set<Integer>>(); 
verticalStrips =printStripsVertically(root,verticalStrips,0);//where root is the root of the tree.
added 582 characters in body
Source Link
seeker
  • 125
  • 5

Edit : TreeNode.java

public class TreeNode {

     int data;
    private TreeNode left;
    private TreeNode right;
    public TreeNode getLeft() {
        return left;
    }
    public void setLeft(TreeNode left) {
        this.left = left;
    }
    public TreeNode getRight() {
        return right;
    }
    public void setRight(TreeNode right) {
        this.right = right;
    }
     
    
    public TreeNode(int data)
    {
        this.data=data;
        this.setLeft(null);
        this.setRight(null);
    }
    
}

I've dry-tested the algorithm to work, but I'm not quite convinced that iterating over the leftMap and rightMap is the cleanest way to go about this, so I'm looking for any suggestions towards that in particular or the code in general.

I've dry-tested the algorithm to work, but I'm not quite convinced that iterating over the leftMap and rightMap is the cleanest way to go about this, so I'm looking for any suggestions towards that in particular or the code in general.

Edit : TreeNode.java

public class TreeNode {

     int data;
    private TreeNode left;
    private TreeNode right;
    public TreeNode getLeft() {
        return left;
    }
    public void setLeft(TreeNode left) {
        this.left = left;
    }
    public TreeNode getRight() {
        return right;
    }
    public void setRight(TreeNode right) {
        this.right = right;
    }
     
    
    public TreeNode(int data)
    {
        this.data=data;
        this.setLeft(null);
        this.setRight(null);
    }
    
}

I've dry-tested the algorithm to work, but I'm not quite convinced that iterating over the leftMap and rightMap is the cleanest way to go about this, so I'm looking for any suggestions towards that in particular or the code in general.

added 8 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

I'm trying to print a binary tree in vertical strips.

For instance, a tree like this  :

       8
     /   \
    6     10
   / \   /  \
  4   7 9    12
 / \
3   5
       8
     /   \
    6     10
   / \   /  \
  4   7 9    12
 / \
3   5
3
4
6 5
8 7 9
10
12
3
4
6 5
8 7 9
10
12

Here's how I'm doing it .:

I've dry-tested the algorithm to work.

But, but I'm not quite convinced that iterating over the leftMap and rightMap is the cleanest way to go about this, so I'm looking for any suggestions towards that in particular or the code in general.

I'm trying to print a binary tree in vertical strips

For instance a tree like this  :

       8
     /   \
    6     10
   / \   /  \
  4   7 9    12
 / \
3   5
3
4
6 5
8 7 9
10
12

Here's how I'm doing it .

I've dry-tested the algorithm to work.

But I'm not quite convinced that iterating over the leftMap and rightMap is the cleanest way to go about this, so I'm looking for any suggestions towards that in particular or the code in general.

I'm trying to print a binary tree in vertical strips.

For instance, a tree like this:

       8
     /   \
    6     10
   / \   /  \
  4   7 9    12
 / \
3   5
3
4
6 5
8 7 9
10
12

Here's how I'm doing it:

I've dry-tested the algorithm to work, but I'm not quite convinced that iterating over the leftMap and rightMap is the cleanest way to go about this, so I'm looking for any suggestions towards that in particular or the code in general.

Source Link
seeker
  • 125
  • 5
Loading