A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/df/d82/breadth__first__search_8cpp_source.html below:

TheAlgorithms/C++: graph/breadth_first_search.cpp Source File

Go to the documentation of this file. 97

std::map<T, bool> visited;

101

visited[adjlist.first] =

false

;

103

visited[

node

] =

false

;

108

std::queue<T> tracker;

113

visited[src] =

true

;

114 while

(!tracker.empty()) {

117

T

node

= tracker.front();

123 if

(!visited[neighbour]) {

125

tracker.push(neighbour);

127

visited[neighbour] =

true

;

141

std::map<int, bool> correct_result;

145

correct_result[0] =

true

;

146

correct_result[1] =

true

;

147

correct_result[2] =

true

;

148

correct_result[3] =

true

;

150

std::map<int, bool> returned_result = g.breadth_first_search(2);

152

assert(returned_result == correct_result);

153

std::cout <<

"Test 1 Passed..."

<< std::endl;

156

returned_result = g.breadth_first_search(0);

158

assert(returned_result == correct_result);

159

std::cout <<

"Test 2 Passed..."

<< std::endl;

164

g2.

add_edge

(

"Gorakhpur"

,

"Lucknow"

,

false

);

165

g2.

add_edge

(

"Gorakhpur"

,

"Kanpur"

,

false

);

166

g2.

add_edge

(

"Lucknow"

,

"Agra"

,

false

);

167

g2.

add_edge

(

"Kanpur"

,

"Agra"

,

false

);

168

g2.

add_edge

(

"Lucknow"

,

"Prayagraj"

,

false

);

169

g2.

add_edge

(

"Agra"

,

"Noida"

,

false

);

171

std::map<std::string, bool> correct_res;

172

std::map<std::string, bool> returned_res =

174

correct_res[

"Gorakhpur"

] =

false

;

175

correct_res[

"Lucknow"

] =

false

;

176

correct_res[

"Kanpur"

] =

true

;

177

correct_res[

"Agra"

] =

true

;

178

correct_res[

"Prayagraj"

] =

false

;

179

correct_res[

"Noida"

] =

true

;

180

assert(correct_res == returned_res);

181

std::cout <<

"Test 3 Passed..."

<< std::endl;

188

std::cout <<

"Enter the number of edges: "

;

193

std::cout <<

"Enter space-separated pairs of vertices that form edges: " 201

g.breadth_first_search(0);

std::map< T, bool > breadth_first_search(T src)

void add_edge(T u, T v, bool bidir=true)

std::map< T, std::list< T > > adjacency_list


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4