Question: Data Structure in C++ I wrote the code for implementing the adjacency list, but I dont know to write breadth first search with this please

Data Structure in C++

I wrote the code for implementing the adjacency list, but I dont know to write breadth first search with this

please help me write the breadth first search with this code. Thank you

/*

* C++ Program to Implement Adjacency List

*/

#include

#include

using namespace std;

struct AdjListNode{ //Adjacency List Node

int dest;

struct AdjListNode* next;

};

struct AdjList{ //Adjacency List

struct AdjListNode* head;

};

class Graph{

private:

int V;

struct AdjList* array;

public:

Graph(int V){

this->V = V;

array = new AdjList [V];

for (int i = 0; i < V; ++i)

array[i].head = NULL;

}

AdjListNode* newAdjListNode(int dest){//create new adjacency list node

AdjListNode* newNode = new AdjListNode;

newNode->dest = dest;

newNode->next = NULL;

return newNode;

}

void addEdge(int src, int dest){ //Add Edge to Graph

AdjListNode* newNode = newAdjListNode(dest);

newNode->next = array[src].head;

array[src].head = newNode;

newNode = newAdjListNode(src);

newNode->next = array[dest].head;

array[dest].head = newNode;

}

void printGraph(){ //print grao

int v;

for (v = 0; v < V; ++v)

{

AdjListNode* pCrawl = array[v].head;

cout<<" Adjacency list of vertex "<

while (pCrawl)

{

cout<<"-> "<dest;

pCrawl = pCrawl->next;

}

cout<

}

}

};

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!