Question

You have to use Binary Tree ADT.

Problem Use Java as Programming Language Define an ESports World Cup class that implements the E-Games World Cup using a Bina

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

As per the given data, the following code would be helpful.

Building a binary tree ADT

A binary tree is a hierarchical data structure whose behavior is similar to a tree, as it contains root and leaves (a node that has no child). The root of a binary tree is the topmost node. Each node can have at most two children, which are referred to as the left child and the right child. A node that has at least one child becomes a parent of its child. A node that has no child is a leaf. Please take a look at the following binary tree:

2 4 5 6 7

Code:

import java.io.*;
import java.util.*;

// This class represents a directed graph using adjacency list  representation
class GraphTry
{
   private int V; // No. of vertices
   private LinkedList<Integer> adj[]; //Adjacency Lists

   // Constructor
   Graph(int v)
   {
       V = v;
       adj = new LinkedList[v];
       for (int i=0; i<v; ++i)
           adj[i] = new LinkedList();
   }

   // Function to add an edge into the graph
   void addEdge(int v,int w)
   {
       adj[v].add(w);
   }

   // prints BFS traversal from a given source s
   void BFS(int s)
   {
       // Mark all the vertices as not visited(By default set as false)
       boolean visited[] = new boolean[V];

       // Creating a queue for BFS
       LinkedList<Integer> queue = new LinkedList<Integer>();

       // Mark the current node as visited and enqueue it
       visited[s]=true;
       queue.add(s);

       while (queue.size() != 0)
       {
           // Dequeueing a vertex from queue and then printing it
           s = queue.poll();
           System.out.print(s+" ");

           /* Get all adjacent vertices of the dequeued vertex s, If a adjacent has not been visited, then mark it visited and enqueue it */
           Iterator<Integer> i = adj[s].listIterator();
           while (i.hasNext())
           {
               int n = i.next();
               if (!visited[n])
               {
                   visited[n] = true;
                   queue.add(n);
               }
           }
       }
   }

   // Main method
   public static void main(String args[])
   {
       GraphTry g = new GraphTry(4);

       g.addEdge(0, 1);
       g.addEdge(0, 2);
       g.addEdge(1, 2);
       g.addEdge(2, 0);
       g.addEdge(2, 3);
       g.addEdge(3, 3);

       System.out.println(" Breadth First "+ "(starting from vertex 2)");

       g.BFS(2);
   }
}

I hope it will be helpful, Please give ThumsUp

Thank you!!

Add a comment
Know the answer?
Add Answer to:
You have to use Binary Tree ADT. Problem Use Java as Programming Language Define an ESports...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Name Final Exam CSC 175 (Intermediate Computer Programming) Dr. David Chays May 14, 2019 You may use your own class notes, the textbook or any standard Java language reference book for this exam....

    Name Final Exam CSC 175 (Intermediate Computer Programming) Dr. David Chays May 14, 2019 You may use your own class notes, the textbook or any standard Java language reference book for this exam. Total points for this exam are 100. Problem 1 (15 pts) For a game, you are designing a World that has a collection of players. There are two kinds of players: Superhero and Jedi (i.e. a Superhero is a Player, and a Jedi is a Player) Each...

  • using java to write,show me the output. please write some common. You CAN NOT use inbuild...

    using java to write,show me the output. please write some common. You CAN NOT use inbuild functions for Tree ADT operations. using code below to finsih public class Main {    public static void main(String[] args) {        BinaryTree tree = new BinaryTree(); tree.root = new Node(1); tree.root.left = new Node(2); tree.root.right = new Node(3); tree.root.left.left = new Node(4); tree.root.left.right = new Node(5); tree.root.right.left = new Node(6); tree.root.right.right = new Node(7); tree.root.left.left.left = new Node(8); tree.root.left.left .right= new Node(9);...

  • Problem Statement: A company intends to offer various versions of roulette game and it wants you...

    Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...

  • You will implement 2 games, the Prisoner's Dilemma, The Stag Hunt and compare their results for...

    You will implement 2 games, the Prisoner's Dilemma, The Stag Hunt and compare their results for your report. After you finish implementing everything else, you will only need to change one function to make it a prisoner's dilemma or a stag hunt game 1) main.cpp: This is the driver program that sets up the game and plays it. This is where you will call functions to print the statistics. The required statistics is percentage of players using strategy 1 (cooperate...

  • hello there, i have to implement this on java processing. can someone please help me regarding...

    hello there, i have to implement this on java processing. can someone please help me regarding that? thanks War is the name of a popular children’s card game. There are many variants. After playing War with a friend for over an hour, they argue that this game must never end . However! You are convinced that it will end. As a budding computer scientist, you decide to build a simulator to find out for sure! You will implement the logic...

  • I have this case study to solve. i want to ask which type of case study...

    I have this case study to solve. i want to ask which type of case study in this like problem, evaluation or decision? if its decision then what are the criterias and all? Stardust Petroleum Sendirian Berhad: how to inculcate the pro-active safety culture? Farzana Quoquab, Nomahaza Mahadi, Taram Satiraksa Wan Abdullah and Jihad Mohammad Coming together is a beginning; keeping together is progress; working together is success. - Henry Ford The beginning Stardust was established in 2013 as a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT