data structure for graph

S

Sameer

Hello,

A data structure for the implementation of graph can be

struct node
{
int index;
struct node *next;
};

struct adjnode // node adjacent to node
{
int adjindex;
struct node *next;
struct adjnode *next;
};


input file is

node1 adjnode1 adjnode3
node2 adjnode1 adjnode4
node3 adjnode1 adjnode4
node3 adjnode2 adjnode3

such that 1234 forms a quadrilateral.

How can I populate all the data in one file read...


Kindly reply,
Regards,
Sameer.
 
S

Sameer

Sameer said:
Hello,

A data structure for the implementation of graph can be

struct node
{
int index;
struct node *next;
};

struct adjnode // node adjacent to node
{
int adjindex;
struct node *next;
struct adjnode *next;
};


input file is

node1 adjnode1 adjnode3
node2 adjnode1 adjnode4
node3 adjnode1 adjnode4
node3 adjnode2 adjnode3

such that 1234 forms a quadrilateral.

How can I populate all the data in one file read...


Kindly reply,
Regards,
Sameer.
sorry the currect input file is

node1 adjnode2 adjnode3
node2 adjnode1 adjnode4
node3 adjnode1 adjnode4
node4 adjnode2 adjnode3
 
I

Ivan Vecerina

Hi Sameer,
....
| > A data structure for the implementation of graph can be
| >
| > struct node
| > {
| > int index;
| > struct node *next;
| > };
| >
| > struct adjnode // node adjacent to node
| > {
| > int adjindex;
| > struct node *next;
| > struct adjnode *next;
| > };
....
| sorry the currect input file is
|
| node1 adjnode2 adjnode3
| node2 adjnode1 adjnode4
| node3 adjnode1 adjnode4
| node4 adjnode2 adjnode3

Unfortunately, your question remains too vague.
There are many kinds of graphs (cyclic/acyclic,
oriented or not, ...), and even more ways
to represent them using different data structures.

From your post, I still do not understand how
struct node and struct adjnode are intended to
be used.

I think you need to tell more about your
goals/constraints/requirements.


Regards,
Ivan
 
M

Malcolm

Sameer said:
A data structure for the implementation of graph can be

struct node
{
int index;
struct node *next;
};

struct adjnode // node adjacent to node
{
int adjindex;
struct node *next;
struct adjnode *next;
};


input file is

node1 adjnode1 adjnode3
node2 adjnode1 adjnode4
node3 adjnode1 adjnode4
node3 adjnode2 adjnode3

such that 1234 forms a quadrilateral.

How can I populate all the data in one file read...
If you're only allowed to make one call to a read function, the only thing
you can do is read to a temporary buffer. This doesn't really answer ypur
question.

It looks like each line starts with a terminal node, then contains an
arbitrary number of adjnodes that point to the terminal node, and to another
adjnode.
However what I don't understand is that you seem to have declared 8
adjnodes, yet the maximum index is four. Are you sure that adjnodes don't
actually contain two adjnode pointers?
 
B

Barry Schwarz

Hello,

A data structure for the implementation of graph can be

struct node
{
int index;
struct node *next;
};

struct adjnode // node adjacent to node
{
int adjindex;
struct node *next;
struct adjnode *next;
};

There can be only one member named next is struct adjnode. Perhaps
you would like to call these two pointer n_next and a_next.



<<Remove the del for email>>
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top