Jump to content

ΚΩΔΙΚΑΣ C++ (σωστό linking και επεξήγηση κάποιων εντολώ


maxitis
 Κοινοποίηση

Recommended Posts

Από τον παρακάτω κώδικα θέλουμε σωστό linking και επεξήγηση κάποιων εντολών αντικειμενοστραφούς προγραμματισμού(Cobject,Cobarray κλπ) και σε δεύτερη φάση πιο μελλοντικά κατάλληλες προσθήκες ούτως ώστε να επιλύει ένα FAP(frequency assignment problem).

Όποιος ξέρει ας στείλει pm.

Eyxaristo. :)

 

 

#include <afxwin.h>

 

class node:public CObject

{

public:

int color;

CObArray *nodes;

node(){color=0;nodes=new CObArray;}

~node(){nodes->RemoveAll();delete nodes;}

};

 

class graph:public CObject

{

public:

CObArray *nodes;

graph(){nodes=new CObArray;}

~graph(){for(int i=0;i<nodes->GetSize();i++){delete (*nodes);}nodes->RemoveAll();delete nodes;}

void relate(int i,int j)

{

node *n1=(node*)(*nodes)[i-1];

node *n2=(node*)(*nodes)[j-1];

n1->nodes->Add(n2);

n2->nodes->Add(n1);

}

void greedy()

{

for(int i=0;i<nodes->GetSize();i++)

{

node *n=(node*)(*nodes);

BOOL exit=TRUE;

while(exit)

{

int count=1;

BOOL loop=TRUE;

while(loop)

{

for(int j=0;j<n->nodes->GetSize();j++)

{

node *m=(node*)(*n->nodes)[j];

if(m->color==count) break;

}

if(j==n->nodes->GetSize()) {n->color=count;exit=FALSE;loop=FALSE;}

else count++;

}

}

}

}

};

 

void main()

{

graph g;

for(int i=0;i<10;i++)

{

node *n=new node;g.nodes->Add(n);

}

g.relate(1,7);

g.relate(1,9);

g.relate(1,10);

g.greedy();

int cc=1;

for(i=0;i<g.nodes->GetSize();i++)

{

node *n=(node*)(*g.nodes);

if(n->color>cc) cc=n->color;

TRACE("%d\t%d\n",i+1,n->color);

}

TRACE("%d\n",cc);

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Επισκέπτης
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Κοινοποίηση

×
×
  • Create New...