Code is given below :
#include <cstdio>
#include <iostream>
#include <deque>
struct vertex {
bool visited;
int value;
int distance;
};
int main() {
int key_value;
std::cin >> key_value;
int num_vertices;
std::cin >> num_vertices;
int** matrix;
matrix = new int*[num_vertices];
for (int i = 0; i < num_vertices; i++) {
matrix[i] = new int[num_vertices];
}
vertex* vertices;
vertices = new vertex[num_vertices];
std::deque<vertex> queue;
int vertex, value;
while(std::cin >> vertex >> value) {
vertices[vertex].value = value;
int num_edges;
std::cin >> num_edges;
for(int i = 0; i < num_edges; i++) {
int edge_to;
std::cin >> edge_to;
matrix[vertex][edge_to] = 1;
}
}
//BFS
vertices[0].visited = true;
vertices[0].distance = 0;
queue.push_back(vertices[0]);
while(!queue.empty()) {
vertex cur_v;
cur_v = queue.front();
queue.pop_front();
for(int i = 1; i < num_vertices; i++) {
if(matrix[cur_v, i]) {
if(!vertices[i].visited) {
vertices[i].visited = true;
queue.push_back(vertices[i]);
}
}
}
}
return(0);
}
I am getting the following errors,
search_gilene_matt.cc: In function ‘int main()’: search_gilene_matt.cc:42: error: expected ‘;’ before ‘cur_v’ search_gilene_matt.cc:43: error: ‘cur_v’ was not declared in this scope
Can someone shed some light on what would be causing this?
I have looked for a missing semicolon but I don't have any idea of where it would be.
cur_v, ishouldn't use the comma operator... you want][. Separately, compilers tend to do something really helpful - tell you the line number the error's on. How about putting a big// ERROR HERE!in your code listing...?int vertex, value;shadows the typevertex