I’m trying to create a combination of graph edges which are stored inside a vector. I need to generate AND store the generated vectors in a vector as well. Below is what I have done so far but it is not compiling at the moment;
#include <stdlib.h>
#include<iostream>
#include<vector>
#include<algorithm>
struct edge{
int a;
int b;
int weight;
edge(int u,int v,int cost)
{
a=u;
b=v;
weight=cost;
}
};
int main()
{
typedef std::vector<edge> V; //<or_any_class>
V v;
v.push_back(1,2,10);
v.push_back(1,3,10);
v.push_back(1,4,10);
v.push_back(3,4,10);
v.push_back(3,5,10);
v.push_back(3,5,10);
do{
std::cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<" "<<v[3]<<" "<<v[4]<<std::endl;
}
while(std::next_permutation(v.begin(),v.end()));
return 0;
}
What Im trying to get as output;
1 2
1 3
1 4
3 4
3 5
4 3
1 2 1 3
1 2 1 4
Any hints?
Error one:
should be
Error two:
You need to define
operator <<for youredgeclass so thatstd::cout<<v[0]can compileError three:
You need to define
operator <for youregdeclass so thatstd::next_permutation(v.begin(),v.end())can compile and work