We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Used in-order traversal technique on binary search tree
/* Hidden stub code will pass a root argument to the function below. Complete the function to solve the challenge. Hint: you may want to write one or more helper functions. The Node class is defined as follows: class Node { int data; Node left; Node right; }*/publicstaticNodeprevNode=null;booleancheckBST(Noderoot){booleanflag=true;returninOrderTraversal(root,flag);}publicstaticbooleaninOrderTraversal(Nodenode,booleanflag){if(node.left!=null){flag=inOrderTraversal(node.left,flag);}if(prevNode!=null&&prevNode.data>=node.data)flag=false;prevNode=node;if(node.right!=null){flag=inOrderTraversal(node.right,flag);}returnflag;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Trees: Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Used in-order traversal technique on binary search tree