bool Graph::searchNeighbors (int nodeId, int neighborId) { Node* current = vertices[nodeId]; while (current != nullptr) { if (current->data == neighborId) { return true; current = current->next; } } } return false; void Graph::loadGraph(string edgeListFileName){ ifstream file(edgeListFileName); int u, v; if (file.is_open()) { while (file >> u » v) { addNeighbor (u, v); file.close(); } } } void Graph::dumpGraph(string adj ListFileName) { ofstream file(adj ListFileName); if (file.is_open() ) { for (size_t i = 0; i < vertices.size(); i++) { file << i << ": "; Node* current = vertices[i]; while (current != nullptr) { } file << current->data << " "; current = current->Next; file << endl; } file.close(); } } Test 4: Toy graph, adjacency list (0/2) Test failed!

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 18RQ
icon
Related questions
Question
100%
bool Graph::searchNeighbors (int nodeId, int neighborId) {
Node* current = vertices[nodeId];
while (current != nullptr) {
if (current->data == neighborId) {
return true;
current = current->next;
}
}
}
return false;
void Graph::loadGraph(string edgeListFileName){
ifstream file(edgeListFileName);
int u, v;
if (file.is_open()) {
while (file >> u » v) {
addNeighbor (u, v);
file.close();
}
}
}
void Graph::dumpGraph(string adj ListFileName) {
ofstream file(adj ListFileName);
if (file.is_open() ) {
for (size_t i = 0; i < vertices.size(); i++) {
file << i << ": ";
Node* current = vertices[i];
while (current != nullptr) {
}
file << current->data << " ";
current = current->Next;
file << endl;
}
file.close();
}
}
Transcribed Image Text:bool Graph::searchNeighbors (int nodeId, int neighborId) { Node* current = vertices[nodeId]; while (current != nullptr) { if (current->data == neighborId) { return true; current = current->next; } } } return false; void Graph::loadGraph(string edgeListFileName){ ifstream file(edgeListFileName); int u, v; if (file.is_open()) { while (file >> u » v) { addNeighbor (u, v); file.close(); } } } void Graph::dumpGraph(string adj ListFileName) { ofstream file(adj ListFileName); if (file.is_open() ) { for (size_t i = 0; i < vertices.size(); i++) { file << i << ": "; Node* current = vertices[i]; while (current != nullptr) { } file << current->data << " "; current = current->Next; file << endl; } file.close(); } }
Test 4: Toy graph, adjacency list (0/2)
Test failed!
Transcribed Image Text:Test 4: Toy graph, adjacency list (0/2) Test failed!
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT