adjacency list question

Printable View

• 10-30-2008
lord
adjacency list question
For a current project I am creating I decided the best way to implement the code would be through an adjacency list. I am just simply confused on what the structs would look like and how to create the reference. For example,

Code:

```[Vertex] [Adjacent Vertices]     A            C,B,E     B            C     C            A,B,E     D            E     E            A,C A->C->B->E | B->C | C->A->B->E   ...etc...```
I have one struct for all the vertices and another struct for the adjacent vertices. I need to be able to travel from vertex a to the adjacent vertex b, for example, but b should be a reference to the vertex node b so that I can "jump" from the adjacent vertice chain to the vertex chain.

My structs are setup as follows:

Code:

```struct adj_node {        char vertex;       adj_node* path; //for the adjacency vertex chain (A->C->B->E) }; struct node {     char vertex;     adj_node* next;     node* down; //to travel down the vertex chain (A-B-C) };```
So what I am wondering is do my structs look setup correctly and how would I do the jumping from an adajcency vertex to a vertex?
• 10-30-2008
tabstop
Why wouldn't you just have nodes, which have a char vertex and a node** next which would be a dynamic array of pointers? You would then have that node[0] (and perhaps node[1], etc.) would be pointers to adjacent nodes; following a path might then look like current = current->next[0], or the like. You would also want int number_of_paths or something so that you know how big your next array is.