Skip to content
Snippets Groups Projects
Commit 0ead5ea7 authored by Tüske's avatar Tüske
Browse files

id err

parent 7060ca83
Branches
No related tags found
No related merge requests found
......@@ -16,13 +16,16 @@ private:
int ID;
public:
node(T&& t):t(t),ID(_id++){}
node(T&& t):t(std::move(t)),ID(_id++){}
node(const T& t):t(t),ID(_id++){}
node(node&)=delete;
node(const node&)=delete;
node(node&&)=default;
node& operator=(const node&)=delete;
node& operator=(node&&) =default;
T& data() { return t; }
int id() { return ID; }
......@@ -32,9 +35,9 @@ private:
class connection
{
public:
connection(node* a, node *b):A(a),B(b){}
node * A;
node * B;
connection(node* a, node *b):A(a),B(b){}
};
std::vector<node> nodes{};
......@@ -44,7 +47,9 @@ public:
graph(){}
node& add_node(T &&t) { nodes.push_back(node(std::move(t))); }
node& add_node(T &&t) {
nodes.push_back(node(std::move(t)));
}
node& add_node(T& t) {nodes.push_back(node(t));}
......@@ -54,22 +59,27 @@ public:
{
bool foundn=false;
bool foundo=false;
std::cout<<std::endl<<n.id()<<std::endl;
for(auto& i : nodes)
{
std::cout<<std::endl<<i.id()<<std::endl;
if(i.id()==n.id())
foundn=true;
if(i.id()==o.id())
foundo=true;
}
if(!foundn || !foundo)
{
std::cout<<foundn<<":"<<foundo;
return;
}
connections.push_back(connection{&n,&o});
}
void erase(node& n)
{
for(auto i =std::begin(connections);i!=std::end(connections);i++)
for(auto&& i =std::begin(connections);i!=std::end(connections);i++)
if( i->A->id() == n.id() || i->B->id() == n.id() )
if(i==std::begin(connections))
{
......@@ -80,7 +90,7 @@ public:
else
connections.erase(i);
for(auto i =std::begin(nodes);i!=std::end(nodes);i++)
for(auto&& i =std::begin(nodes);i!=std::end(nodes);i++)
if(i->id()==n.id())
if(i==std::begin(nodes))
{
......@@ -98,7 +108,7 @@ public:
std::vector<node*> get_childs(node& n)
{
std::vector<node*> ret{};
for(auto i : connections)
for(auto& i : connections)
{
if(n.id()==i.A->id())
ret.push_back(i.B);
......@@ -120,9 +130,10 @@ int main()
auto& t2=g.add_node(6);
std::cout<<g[0].data();
auto& t = g.add_node(52);
std::cout<<std::endl<<t.id()<<std::endl;
g.connect(t,g[0]);
//g.connect(t,t2);
std::cout<<g.get_childs(t).size();
std::cout<<std::endl<<g.get_childs(t).size();
g.erase(t);
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment