When I try to run this program there is a segmentation fault that is caused in this section:
std::vector<double> dist1(dist);
dist1.erase(std::remove(dist1.begin(), dist1.end(), 0), dist1.end());
max = *std::max_element(dist1.begin(),dist1.end());
min = *std::min_element(dist1.begin(),dist1.end());
It is the use of the max_element() and min_element() that cause the segmentation fault but I do not see why. What I doing here is copying a vector "dist" to "dist1", removing all occurrences of "0" in the new vector and then searching for the minimum and maximum values from the remaining items in "dist" "max" and "min" are double type variables previously declared. "dist" is previously declared as
std::vector<double> dist; //vector used to hold the distances between adjacent vertices
dist.resize(size);
The code compiles otherwise with g++ on a Linux server. Please advice.