Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with a conceptual graph

Daniel Ladd
Guest
 
Posts: n/a
#1: Jul 22 '05

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

--
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

puppet_sock@hotmail.com
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Problem with a conceptual graph


"Daniel Ladd" <se_lachiedi@te_la_dico.it> wrote in message news:<opsbd9hjsdxblvrs@localhost.localdomain>...[color=blue]
> Hi,
> I have a problem with a conceptual graph in c++.
> I have a list of structures like this:
> typedef struct Conceptual
> {[/color]
char* Name;//Rappresenta la parola da mettere nel grafo[color=blue]
> Conceptual* Next;
> Conceptual()
> {Next=NULL;
> Name=NULL;
> }
> };[/color]

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
Daniele
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Problem with a conceptual graph


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
On 19 Jul 2004 15:02:41 -0700, <puppet_sock@hotmail.com> wrote:
[color=blue]
> "Daniel Ladd" <se_lachiedi@te_la_dico.it> wrote in message
> news:<opsbd9hjsdxblvrs@localhost.localdomain>...[color=green]
>> Hi,
>> I have a problem with a conceptual graph in c++.
>> I have a list of structures like this:
>> typedef struct Conceptual
>> {[/color]
> char* Name;//Rappresenta la parola da mettere nel grafo[color=green]
>> Conceptual* Next;
>> Conceptual()
>> {Next=NULL;
>> Name=NULL;
>> }
>> };[/color]
>
> 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[/color]



--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Karl Heinz Buchegger
Guest
 
Posts: n/a
#4: Jul 22 '05

re: Problem with a conceptual graph


Daniele wrote:[color=blue]
>
> Because I never made one and it's the only way that I know to manage a
> list of structures.[/color]

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;
}
[color=blue]
> Can you help me?[/color]

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

--
Karl Heinz Buchegger
kbuchegg@gascad.at
Brian McGuinness
Guest
 
Posts: n/a
#5: Jul 22 '05

re: Problem with a conceptual graph


"Daniel Ladd" <se_lachiedi@te_la_dico.it> wrote in message news:<opsbd9hjsdxblvrs@localhost.localdomain>...[color=blue]
> 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
>
> --[/color]

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
Closed Thread


Similar C / C++ bytes