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 friends; public Student(String name, double age, int zipcode) { this.name = name; this.age = age; this.zipcode = zipcode; friends = new MyGenericLinkedList(); } public String toString() { return "(" + name + ", " + age + ", " + zipcode + ")"; } }

class GraphWithAdjacencyList { MyGenericLinkedList studentList; public GraphWithAdjacencyList(Student[] s) { studentList = new MyGenericLinkedList(); for(int i = 0; i < s.length; i++) { studentList.add(s[i]); } } public void addEdge(Student x, Student y) { x.friends.add(y); y.friends.add(x); } public void breadthFirstSearch(Student start) { System.out.println("--- Breadth First Search ---"); // Fill in your code here

} 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 { private Node front; private Node back;

public MyGenericQueue() { front = null; back = null; }

public void add(T data) { Node temp = back; back = new Node(data); if(front == null) front = back; else temp.next = back; } public T peek() { if(front == null) return null; return front.data; }

public T remove() { if(front == null) return null;

Node temp = front; front = front.next; if(front == null) back = null; return (T)temp.data; } }

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 { X data; Node next;

public Node(X data) { this.data = data; this.next = null; }

public Node(X data, Node next) { this.data = data; this.next = next; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!