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!
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!
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 18RQ
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();
}
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd0dac0b6-5a17-4cd9-bac9-9e2e50ac9cbc%2Fc533aff1-87b9-4112-999c-67fb9274091a%2Ff0obb8d_processed.png&w=3840&q=75)
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();
}
}

Transcribed Image Text:Test 4: Toy graph, adjacency list (0/2)
Test failed!
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

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
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

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
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT