Я только что выучил Дейкстру в школе, но мне хотелось попробовать написать его код. У меня проблема с итератором и изменением конкретной точки вектора, но скорее всего моя реализация неправильная. Ошибка, которую я получаю, приведена ниже, и мне интересно, как изменить объект std::pair на объект std::_vector_iterator. Кроме того, что означает _Scary_val?
Моя ошибка:
Я только что выучил Дейкстру в школе, но мне хотелось попробовать написать его код. У меня проблема с итератором и изменением конкретной точки вектора, но скорее всего моя реализация неправильная. Ошибка, которую я получаю, приведена ниже, и мне интересно, как изменить объект std::pair на объект std::_vector_iterator. Кроме того, что означает _Scary_val? Моя ошибка: [code]no suitable conversion function from "std::pair" to "std::_Vector_iterator::value_type" (aka "Node *") exists [/code] Мой файл заголовка [code]#pragma once #include #include class Node; class Graph; class Edge;
class Edge { public: Node* from; Node* to; int weight; //bool directional; Edge() = default;
Edge(Node* to, Node* from, int weight, bool directional); };
void Graph::printGraph() { //this will call Node::printConnections for (auto& Node : this->GraphNodes) { Node->printConnections(); } }
void Node::printConnections() { for (auto& Node : this->conncections) { cout name name conncections) { //goes through connections which hold edges for that node
if (std::find(visited.begin(), visited.end(), node->to) != visited.end()) continue; //this is checking if the node is already visited
auto temp = std::make_pair(node->to, node->weight + current.second); int i = 0; while (i != notVisited.size() && notVisited[i].second < temp.second) { i++; } notVisited.insert(notVisited.begin() + i, temp); //inserts the element in the right place visited.push_back(node->from); //adds it to visited
auto it = (std::find(visited.begin(), visited.end(), node->to));