Page 1 of 1

Implement method. public void printAllLeaves() Using Queue to print all leaf nodes of a binary tree public interface Q

Posted: Fri May 20, 2022 10:16 am
by answerhappygod
Implement method. public void printAllLeaves()
Using Queue to print all leaf nodes of a binary
tree
public interface Queue<E> { // interface is a blueprint of
class contains methods without implemenation
//A Blueprint Interface is a collection of one
or more functions
/** Returns the number of elements in the queue.
*/
int size( );
/** Tests whether the queue is empty. */
boolean isEmpty( );

/** Inserts an element at the rear of the queue.
*/
void enqueue(E e);

/** Returns, but does not remove, the first
element of the queue (null if empty). */
E first( );

/** Removes and returns the first element of the
queue (null if empty). */
E dequeue( );
}
public class Tree<E> {
private Node<E> root;
}
public class Node <E> {
int key;
E data;
Node<E> leftChild;
Node<E> rightChild;

public E getData() {
return data;
}
public Node(int k,E e)
{
key=k;
data=e;
leftChild=null;
rightChild=null;
}
public void display() {
System.out.print(key+":");
System.out.println(data);

}
}