Day 21: Generics :
//Write your code here
static <E> void printArray( E[] inputArray)
{
for( E e : inputArray)
{
System.out.println(""+e);
}
}
Day 22: Binary Search Trees :
public static int getHeight(Node root){
//Write your code here
if(root ==null)
return -1;
int left=getHeight(root.left);
int right=getHeight(root.right);
return Math.max(left, right) + 1;
}
Day 23: BST Level-Order Traversal :
static void levelOrder(Node root){
//Write your code here
Queue<Node> queue = new LinkedList<Node>();
queue.add(root);
while(queue.peek()!=null)
{
Node node =queue.remove();
System.out.print(""+node.data+" ");
if(node.left!=null)
queue.add(node.left);
if(node.right!=null)
queue.add(node.right);
}
}
//Write your code here
static <E> void printArray( E[] inputArray)
{
for( E e : inputArray)
{
System.out.println(""+e);
}
}
Day 22: Binary Search Trees :
public static int getHeight(Node root){
//Write your code here
if(root ==null)
return -1;
int left=getHeight(root.left);
int right=getHeight(root.right);
return Math.max(left, right) + 1;
}
Day 23: BST Level-Order Traversal :
static void levelOrder(Node root){
//Write your code here
Queue<Node> queue = new LinkedList<Node>();
queue.add(root);
while(queue.peek()!=null)
{
Node node =queue.remove();
System.out.print(""+node.data+" ");
if(node.left!=null)
queue.add(node.left);
if(node.right!=null)
queue.add(node.right);
}
}
No comments:
Post a Comment