0

below is my current code and i'm having trouble implementing the addvertex function, i'm not too sure where to start as i am fairly new to c++ any help would be appreciated. I was told using a map would be the simplest way of doing this.

the graph needs to compute the minimum spanning tree, depth and breadth first traversals, and implementing iterators.

the addvertex function will addthe passed vertex to the graph (with no edges).

#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&);
Dan
  • 89
  • 8
  • You need to store vertices in some container member variable, such as `std::vector vertices_;`. The suitable type of container depends heavily on what operations your `weighted_graph` should support (insertion, removal, lookup, traversing,...). – Daniel Langr May 09 '18 at 14:40
  • what would you recommend as some operations that need to be supported are computing the minimum spanning tree, depth and breadth first traversals, and implementing iterators. – Dan May 09 '18 at 14:45
  • 1
    Creating a graph class is an enormous amount of work with numerous pitfalls. Not a good idea for a starter project when learning C++! Suggest trying something easier, or else finding an open source graph class on github and experimenting with that. – ravenspoint May 09 '18 at 15:10

0 Answers0