1

I've been trying to create an Adjancey List with an undirected graph. Everything is going smoothly, except for when I need to have a Node(or vertex as in my code) have multiple edges connected to it. I have 6 vertexs A,B,C,D,E,F and there's only edges from A to B, A to C, A to D this is what it looks like conceptually. I've been trying over and over to come up with an algorithm to connect more than one edge together, I can't figure it out. Here is my structures for reference, and where my else statement is where I need to walk through to the end of the linked edges and attach the new edge.

typedef struct
{
    char c;
    bool isVisited;
    struct EDGETAG* p;
} VERTEX;

typedef struct EDGETAG
{
    VERTEX* v;
    struct EDGETAG* next;
} EDGE;

//~~~~~~~~
while( fgets(data,sizeof(data),filePtr) && elements < 50)
    {
        startPtr = data;
        EDGE* e  = (EDGE*)malloc(sizeof(EDGE));
        //first character
        int breakLogic = 0;
        int i;

        for( i = 0; i < 50; i++)
        {
            if(map[i].c == *startPtr)
            {
                elements = i;
                break;
            }
        }
        //first character
        map[elements].c = *startPtr;
        printf("%i %c\n",elements,map[elements].c);
        //point first character to edge
        if(map[elements].p == NULL)
        {
            map[elements].p = e;
        }
        else
        {
             /*Here is where I need help*/
        }

        startPtr += 2;

        for( i = 0; i < 50; i++)
        {
            if(map[i].c == *startPtr)
            {
                elements = i;
                breakLogic = 1;
                break;

            }

        }
        if( breakLogic == 0)
        {
            elements++;
        }
        //second character
        map[elements].c = *startPtr;
        printf("%i %c\n",elements,map[elements].c);
        //point edge to second character
        e -> v = &map[elements];
        e -> next = NULL;
        //loops at the newline

        elements++;
    }

}
Joshua
  • 11
  • 1

0 Answers0