Question
public static void main(String[] args) { GraphWithAdjacencyList g = new GraphWithAdjacencyList(Student.roster); g.addEdge(Student.roster[0], Student.roster[1]); g.addEdge(Student.roster[0], Student.roster[6]); g.addEdge(Student.roster[0], Student.roster[2]); g.addEdge(Student.roster[0], Student.roster[5]); g.addEdge(Student.roster[1], Student.roster[6]); g.addEdge(Student.roster[1], Student.roster[3]); g.addEdge(Student.roster[1], Student.roster[4]);
public static void main(String[] args) { GraphWithAdjacencyList g = new GraphWithAdjacencyList(Student.roster); g.addEdge(Student.roster[0], Student.roster[1]); g.addEdge(Student.roster[0], Student.roster[6]); g.addEdge(Student.roster[0], Student.roster[2]); g.addEdge(Student.roster[0], Student.roster[5]); g.addEdge(Student.roster[1], Student.roster[6]); g.addEdge(Student.roster[1], Student.roster[3]); g.addEdge(Student.roster[1], Student.roster[4]); g.addEdge(Student.roster[2], Student.roster[3]); g.addEdge(Student.roster[4], Student.roster[8]); g.addEdge(Student.roster[5], Student.roster[9]); g.addEdge(Student.roster[6], Student.roster[7]); g.addEdge(Student.roster[7], Student.roster[8]); System.out.println("--- Roster ---"); System.out.println(g.toString()); g.breadthFirstSearch(Student.roster[0]); System.out.println(); g.depthFirstSearch(Student.roster[0]); } }
class Student { public static Student[] roster = {new Student("A", 20, 10000), new Student("B", 30, 10509, new Student("C", 40, 15070), new Student("E", 35, 10400), new Student("F", 48, 10069), new Student("G", 39, 19080), new Student("H", 60, 10430), new Student("Q", 42, 18111), new Student("Y", 23, 18009), new Student("N", 26, 10700) }; private String name; private double age; private int zipcode; public MyGenericLinkedList
class GraphWithAdjacencyList { MyGenericLinkedList
} public void depthFirstSearch(Student start) { System.out.println("--- Depth First Search ---"); // Fill in your code here } void DFS(Student current, boolean[] visited) { // Fill in your code// } public String toString() { // Fill in your code here
} }
class MyGenericQueue
public MyGenericQueue() { front = null; back = null; }
public void add(T data) { Node
public T remove() { if(front == null) return null;
Node
class MyGenericLinkedList { Node front; int size;
public MyGenericLinkedList() { front = null; size = 0; }
public void add(S value) { if (front == null) { front = new Node(value); size++; } else { Node current = front; while (current.next != null) { current = current.next; } current.next = new Node(value); size++; } } public S get(int index) { if((index < 0) || (index >= size())) return null; Node current = front; for (int i = 0; i < index; i++) { current = current.next; } return (S)current.data; } public int indexOf(S data) { int index = 0; Node current = front; while (current != null) { if(current.data == data) return index; current = current.next; index++; } return -1; }
public void remove(int index) { if((index < 0) || (index >= size())) return; if (index == 0) { front = front.next; size--; } else { Node current = front; for (int i = 0; i < index - 1; i++) { current = current.next; } current.next = current.next.next; size--; } } public int size() { return size; } }
class Node
public Node(X data) { this.data = data; this.next = null; }
public Node(X data, Node
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started