0

下面是我当前的代码,我在实现 addvertex 函数时遇到了麻烦,我不太确定从哪里开始,因为我对 c++ 相当陌生,任何帮助将不胜感激。有人告诉我使用地图是最简单的方法。

该图需要计算最小生成树、深度和广度优先遍历以及实现迭代器。

addvertex 函数会将传递的顶点添加到图中(没有边)。

#ifndef WEIGHTED_GRAPH_H
#define WEIGHTED_GRAPH_H

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <array>
#include <list>
#include <forward_list>
#include <deque>
#include <map>

template <typename vertex>
class weighted_graph {
    private:
    class graph_iterator {
        private:
        public:
            graph_iterator(const weighted_graph &);
            graph_iterator(const weighted_graph &, size_t);
            ~graph_iterator();
            graph_iterator operator=(const graph_iterator&);
            bool operator==(const graph_iterator&) const;
            bool operator!=(const graph_iterator&) const;
            graph_iterator operator++();
            graph_iterator operator++(int);
            const vertex operator*();
            const vertex* operator->();
    };

    class neighbour_iterator {
        private:
        public:
            neighbour_iterator(const neighbour_iterator&);
            neighbour_iterator(const weighted_graph &, const vertex&);
            neighbour_iterator(const weighted_graph &, const vertex&, size_t);
            ~neighbour_iterator();
            neighbour_iterator operator=(const neighbour_iterator& it);
            bool operator==(const neighbour_iterator&) const;
            bool operator!=(const neighbour_iterator&) const;
            neighbour_iterator operator++();
            neighbour_iterator operator++(int);         
            const std::pair<vertex, int> operator*();
            const std::pair<const vertex, int>* operator->();
    };

    public:


    weighted_graph(); 
    ~weighted_graph();

    void add_vertex(const vertex&);
4

0 回答 0