Implement method. public void printByLevel (Queue,Node){}
Using Queue to print levels 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);
}
}
Implement method. public void printByLevel (Queue,Node){} Using Queue to print levels of a binary tree public interface
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am