Time limit error

import java.util.*;
public class Main{

static Scanner scn = new Scanner(System.in);

public static void main(String[] args) {
	Main m = new Main();
	BinaryTree bt = m.new BinaryTree();
	bt.levelOrderZZ();
}

private class BinaryTree {
	private class Node {
		int data;
		Node left;
		Node right;
	}

	private Node root;
	private int size;

	public BinaryTree() {
		this.root = this.takeInput(null, false);
	}

	public Node takeInput(Node parent, boolean ilc) {

		int cdata = scn.nextInt();
		Node child = new Node();
		child.data = cdata;
		this.size++;

		// left
		boolean hlc = scn.nextBoolean();

		if (hlc) {
			child.left = this.takeInput(child, true);
		}

		// right
		boolean hrc = scn.nextBoolean();

		if (hrc) {
			child.right = this.takeInput(child, false);
		}

		// return
		return child;
	}

public void levelOrderZZ(){
levelOrderZZ(this.root);
}
private void levelOrderZZ(Node node) {
Stack s1 = new Stack<>();
Stack s2 = new Stack<>();
s1.push(node);
while(!s1.isEmpty()||!s2.isEmpty()){
while(!s1.isEmpty()){
Node p = s1.pop();
System.out.print(p+"");
if(node.left!=null){
s2.push(node.left);
}
if(node.right!=null){
s2.push(node.right);
}
}
while(!s2.isEmpty()){
Node k = s2.pop();
System.out.print(k+"");
if(node.right!=null){
s1.push(node.right);
}
if(node.left!=null){
s1.push(node.left);
}
}
}
}

}

}

refer to this

public void levelOrderZZ() {
    LinkedList list = new LinkedList<>();
    LinkedList stack = new LinkedList<>();
    list.addLast(this.root);

    int count = 0;

    while (!list.isEmpty()) {
        Node rn = list.removeFirst();

        if (rn != null) {
            System.out.print(rn.data + " ");

            if (count % 2 == 0) {

                stack.addFirst(rn.left);
                stack.addFirst(rn.right);

            } else

            {
                stack.addFirst(rn.right);
                stack.addFirst(rn.left);

            }