Oblig2

 avatar
unknown
plain_text
4 years ago
946 B
7
Indexable
#include <iostream>
#include<vector>

using namespace std;

class graph {

public:

    vector<int>* neighbour;
    int nodeSize;
    
    graph(int Vertex) {
        neighbour = new vector<int>[Vertex];
        nodeSize = Vertex;
    }

    void add_edge(int from, int to) {
        neighbour[from].push_back(to);
    }

    void print() {
        for (int i = 0; i < nodeSize; i++) {
            cout << i << "-->";
            for (auto it : neighbour[i]) {
                cout << it << " ";
            }
            cout << endl;
        }
        cout << endl;
    }
    //sletter den siste kanten som på satt inn på den noden
    void delete_edge(int node) {
        neighbour[node].pop_back();

    }
};

int main() {
    graph g(4);
    g.add_edge(1, 2);
    g.add_edge(1, 0);
    g.add_edge(2, 3);
    g.add_edge(3, 0);

    g.delete_edge(1);
    g.print();
    
    
    return 0;
}
Editor is loading...