Question: / * * This method determines if a BST forms a zig - zag pattern. By this we mean that each node has exactly one

/**
This method determines if a BST forms a zig-zag pattern. By this we mean
that each node has exactly one child, except for the leaf. In addition,
the nodes alternate between being a left and a right child. An empty tree
or a tree consisting of just the root are both said to form a zigzag
pattern. For example, if you insert the elements 10,5,9,6,7 into a
BST in that order. , you will get a zig-zag.
@return True if the tree forms a zigzag and false otherwise.
*/
public boolean isZigZag(){
// TODO: 4 Write this.
if(root == NULL_NODE ||
(root.left == NULL_NODE && root.right == NULL_NODE)){
}
return true;
Node orgroot = root;
// if(root.left != NULL_NODE && root.right != NULL_NODE){
//}
return false;
Node temp = root.right;
root = root.left;
if(root != NULL_NODE){
isZigZag();
}
boolean zigzagLeft = isZigZag();
root = temp;
boolean zigzagRight = isZigZag();
root = orgroot;
}
return zigzagLeft||igzagRight;
public void insert(T e){
}
/ * * This method determines if a BST forms a zig

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!