Skip to content
Snippets Groups Projects
Commit 9558b277 authored by adrian s's avatar adrian s
Browse files

update: avoid pointers

parent ce0ff314
No related branches found
No related tags found
No related merge requests found
...@@ -264,6 +264,15 @@ void make_connection(Liwanze& a, Liwanze& b) ...@@ -264,6 +264,15 @@ void make_connection(Liwanze& a, Liwanze& b)
b.addconn_from(a.get_name()); b.addconn_from(a.get_name());
} }
void make_connection(int a, int b, vector<Liwanze>& lvec)
{
lvec.at(a).addconn_to(lvec.at(b).get_name());
lvec.at(b).addconn_from(lvec.at(a).get_name());
}
void init_connections(vector<Liwanze>& lvac) void init_connections(vector<Liwanze>& lvac)
{ {
make_connection(lvac.at(2), lvac.at(4)); make_connection(lvac.at(2), lvac.at(4));
...@@ -308,14 +317,16 @@ void print_network(vector<Liwanze>& lvac) ...@@ -308,14 +317,16 @@ void print_network(vector<Liwanze>& lvac)
cout << endl; cout << endl;
} }
void user_addconn(vector<Liwanze>& lvac) void user_addconn(vector<Liwanze>& lvec)
{ {
string sLiwanzA{}; string sLiwanzA{};
string sLiwanzB{}; string sLiwanzB{};
bool stringA{false}; bool boolLiwanzeA{false};
bool stringB{false}; bool boolLiwanzeB{false};
Liwanze* a{ nullptr }; //Liwanze* a{ nullptr };
Liwanze* b{ nullptr }; //Liwanze* b{ nullptr };
int iLiwanzA;
int iLiwanzB;
...@@ -334,17 +345,17 @@ void user_addconn(vector<Liwanze>& lvac) ...@@ -334,17 +345,17 @@ void user_addconn(vector<Liwanze>& lvac)
} }
for (auto& n : lvac) for (int i{}; i < lvec.size(); i++ )
{ {
if (n.get_name() == sLiwanzA) if (lvec.at(i).get_name() == sLiwanzA)
{ {
a = &n; iLiwanzA = i;
stringA = true; boolLiwanzeA = true;
} }
} }
if (stringA == false) if (boolLiwanzeA == false)
{ {
cout << "Diese Liwanze existiert nicht! Bitte nochmal versuchen "; cout << "Diese Liwanze existiert nicht! Bitte nochmal versuchen ";
continue; continue;
...@@ -363,27 +374,36 @@ void user_addconn(vector<Liwanze>& lvac) ...@@ -363,27 +374,36 @@ void user_addconn(vector<Liwanze>& lvac)
} }
for (auto& n : lvac) for (int i{}; i < lvec.size(); i++)
{ {
if (n.get_name() == sLiwanzB) if (lvec.at(i).get_name() == sLiwanzB)
{ {
b = &n; iLiwanzB = i;
stringB = true; boolLiwanzeB = true;
} }
} }
if (stringB == false) if (boolLiwanzeB == false)
{ {
cout << "Diese Liwanze existiert nicht! Bitte nochmal versuchen "; cout << "Diese Liwanze existiert nicht! Bitte nochmal versuchen ";
continue; continue;
} }
make_connection(*a, *b); make_connection(lvec.at(iLiwanzA), lvec.at(iLiwanzB));
cout << a->get_name() << ":" << endl;
a->print_tierone();
cout << lvec.at(iLiwanzA).get_name() << ":" << endl;
lvec.at(iLiwanzA).print_tierone();
cout << lvec.at(iLiwanzB).get_name() << ":" << endl;
lvec.at(iLiwanzB).print_tierone();
boolLiwanzeA = false;
boolLiwanzeB = false;
cout << b->get_name() << ":" << endl; //a = nullptr;
b->print_tierone(); //b = nullptr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment