Make a DirectedGraph. Then make a function visitAll(Node startNode). This function needs to return every value if it can get through all the nodes without visiting the nodes more than one time. If it cant do this, return null.

Depth-first-search is also needed.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.ArrayList;

public class DirectedGraph {

static class Node //Node class to hold data
char data; //Char data
ArrayList<Edge> edges; //List of edges leading out from this vertex
boolean discovered; //Check if discovered in DFS function
public Node(char data) // Constructor
edges = new ArrayList<Edge>(); //Initiate edge array = data; //Store data
discovered = false; //Set discovered to false

static class Edge //Edge class, stores starting vertext and ending vertex
Node start;
Node end;

public Edge(Node start, Node end)
this.start = start;
this.end = end;

private int size; //Holds size of graph (in number of vertices)
private ArrayList<Node> nodes; //Node list for graph (edges contained within nodes

public DirectedGraph() //Constructor, set size to 0 and initiate arraylist of nodes
size = 0;
nodes = new ArrayList<Node>();

public void addNode(char data) //Add node to array based on data, increment size
nodes.add(new Node(data));
$40.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats