poprawka laczenia + test polaczenia miedzy wezlami
This commit is contained in:
12
Main.cpp
12
Main.cpp
@@ -6,8 +6,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "Node.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
cout << "Obiekt PC1" << endl;
|
||||||
|
Node pc1;
|
||||||
|
|
||||||
|
cout << "Obiekt PC2" << endl;
|
||||||
|
Node pc2;
|
||||||
|
|
||||||
|
cout << "Lacze PC1 z PC2" << endl;
|
||||||
|
cout << pc1.connectNode(&pc2) << endl;
|
||||||
|
|
||||||
|
cout << "Lacze PC1 z PC2 (ponownie)" << endl;
|
||||||
|
cout << pc1.connectNode(&pc2) << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
18
Node.cpp
18
Node.cpp
@@ -22,17 +22,21 @@ Node::~Node()
|
|||||||
* funkcja symuluje typową sytuację: mamy kartę sieciową, a funkcja connectNode jest podłączeniem wtyczki
|
* funkcja symuluje typową sytuację: mamy kartę sieciową, a funkcja connectNode jest podłączeniem wtyczki
|
||||||
* z jednej strony
|
* z jednej strony
|
||||||
*/
|
*/
|
||||||
bool Node::connectNode(Node *node)
|
bool Node::connectNode(Node *node, bool firstConnected)
|
||||||
{
|
{
|
||||||
vector<Node*>::iterator it = this->connectedNodes.begin();
|
if (!firstConnected)
|
||||||
for (; it != this->connectedNodes.end(); ++it) //sprawdzamy, czy połączenia już przypadkiem nie ma
|
|
||||||
{
|
{
|
||||||
if (*it == node)
|
vector<Node*>::iterator it = this->connectedNodes.begin();
|
||||||
return false;
|
for (; it != this->connectedNodes.end(); ++it) //sprawdzamy, czy połączenia już przypadkiem nie ma
|
||||||
|
{
|
||||||
|
if (*it == node)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->connectedNodes.push_back(node); // podłączamy drugi węzeł
|
this->connectedNodes.push_back(node); // podłączamy drugi węzeł
|
||||||
node->connectNode(this); // podłączamy drugą stronę
|
|
||||||
|
if (!firstConnected)
|
||||||
|
node->connectNode(this, true); // to samo w drugą stronę
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user