Implement method. public void printByLevel (){} Using Queue to print levels of a binary tree public interface Queue {

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Implement method. public void printByLevel (){} Using Queue to print levels of a binary tree public interface Queue {

Post by answerhappygod »

Implement method. public void printByLevel (){}
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);

}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply