Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would I connect a doubly linked list to a graph using object oriented progra

ID: 3818887 • Letter: H

Question

How would I connect a doubly linked list to a graph using object oriented programming using c++? I'm having a hard time because I don't what previous should connect to and the adjacent, I'm creating a maze game .. please give detailed explaination with example
Thank you How would I connect a doubly linked list to a graph using object oriented programming using c++? I'm having a hard time because I don't what previous should connect to and the adjacent, I'm creating a maze game .. please give detailed explaination with example
Thank you
Thank you

Explanation / Answer

The structure of a node in the graph(implemented using adjacency list) is:

struct graphNode
{
int vertex;
struct graphNode *next;
};

The structure of a node in a doubly linked list is:

struct doublyLinkedListNode
{
   int data;
   struct doublyLinkedListNode *next,*prev;
};

Since the graphNode->next will accept address having graphNode as its content, same goes for doublyLinkedListNode->next, you won't be able to point a graphNode to a doubluLinkedListNode and vice-versa.

The only solution here is to use void pointers for next and previous. A void pointer is a pointer that has no associated data type with it. A void pointer can hold address of any type and can be typcasted to any type.

So the new structures would be:

struct graphNode
{
int vertex;
void *next;
};

struct doublyLinkedListNode
{
   int data;
void *next,*prev;
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote