Problem with a conceptual graph

D

Daniel Ladd

Hi,
I have a problem with a conceptual graph in c++.
I have a oist of structures like this:
typedef struct Conceptual
{ char* Name;//Rappresenta la parola da mettere nel grafo
Conceptual* Next;
Conceptual()
{Next=NULL;
Name=NULL;
}
};
If I have a word that it's connected to one or more other words which is
the best choice to define the connections? (I can't know the number of
connectios that there are from a word to the others.)
I have think to create a univocal variable for every word and to create a
dynamic matrix of connections.
There is another way, like, for example create some kind of pointer that,
inside the list of structures, point inside the list at all the words
which that word is connected?

Grazie
Daniele
 
P

puppet_sock

Daniel Ladd said:
Hi,
I have a problem with a conceptual graph in c++.
I have a list of structures like this:
typedef struct Conceptual
{
char* Name;//Rappresenta la parola da mettere nel grafo
Conceptual* Next;
Conceptual()
{Next=NULL;
Name=NULL;
}
};

Okay, first, why use "typedef" here? Why not make a class?

class Conceptual
{
public:
Conceptual()
{Next=NULL;
Name=NULL;
}
private:
Conceptual* Next;
char* Name;//Rappresenta la parola da mettere nel grafo
};

Next, you seem to be making a linked list. Why not use the
list in the standard library?
Socks
 
D

Daniele

Because I never made one and it's the only way that I know to manage a
list of structures.
Can you help me?


Daniele
 
K

Karl Heinz Buchegger

Daniele said:
Because I never made one and it's the only way that I know to manage a
list of structures.

The point is: You don't need to make one. It has already been done
for you, you just need to use it (Same for string management)

#include <iostream>
#include <list>
#include <string>

using namespace std;

struct Conceptual
{
Conceptual( const std::string& Name_ ) : Name( Name_ ) {}
std::string Name;
};

int main()
{
list< Conceptual > MyList;

MyList.push_back( Conceptual( "First" ) );
MyList.push_back( Conceptual( "Second" ) );

list< Conceptual >::iterator it;

for( it = MyList.begin(); it != MyList.end(); ++it )
cout << it->Name << "\n";

cout << endl;
}
Can you help me?

You need to buy some literature and work through it.
look eg. at http://ma.rtij.nl/acllc-c++.FAQ.html)
for some recommendations
 
B

Brian McGuinness

Daniel Ladd said:
Hi,
I have a problem with a conceptual graph in c++.
I have a oist of structures like this:
typedef struct Conceptual
{ char* Name;//Rappresenta la parola da mettere nel grafo
Conceptual* Next;
Conceptual()
{Next=NULL;
Name=NULL;
}
};
If I have a word that it's connected to one or more other words which is
the best choice to define the connections? (I can't know the number of
connectios that there are from a word to the others.)
I have think to create a univocal variable for every word and to create a
dynamic matrix of connections.
There is another way, like, for example create some kind of pointer that,
inside the list of structures, point inside the list at all the words
which that word is connected?

Grazie
Daniele

--

If I understand this correctly, each node may point to any number of other
nodes, and the maximum number of pointers leading away from any given node
is not known in advance. So what is required is not a simple linked list
but a node with a variable number of pointers. I would be inclined to try
using a vector of pointers, for example:

class Conceptual {
private:
std::string Name;
std::vector<Conceptual *> Next;

public:
Conceptual (std::string N) : Name (N) {}

AddLink (Conceptual *L) {
Next.push_back (L);
}

Traverse (Conceptual *H); // Traverse the tree starting at node H
};

and so on.

--- Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top