Computer Science  >  QUESTIONS & ANSWERS  >  University of Colorado, Boulder - CSCI 2270Graph.cpp (All)

University of Colorado, Boulder - CSCI 2270Graph.cpp

Document Content and Description Below

#include <iostream> #include "Graph.hpp" using namespace std; void Graph::addVertex(string name){ bool found = false; for(int i=0;i<vertices.size();i++){ if(vertices[i]->name == name){ found = ... true; } } if(found == false){ vertex* v = new vertex; v->name = name; vertices.push_back(v); } } void Graph::addEdge(std::string v1,std::string v2){ for(int i=0;i<vertices.size();i++){ if(vertices[i]->name == v1){ for(int j=0;j<vertices.size();j++){ if(vertices[j]->name == v2 && i != j){ adjVertex e0; e0.v = vertices[j]; vertices[i]->adj.push_back(e0); adjVertex e1; e1.v = vertices[i]; vertices[j]->adj.push_back(e1); } } } } } void Graph::displayEdges(){ for(int i=0;i<vertices.size();i++){ cout << vertices[i]->name << " --> "; for(int j=0;j<vertices[i]->adj.size();j++){ cout << vertices[i]->adj[j].v->name << " "; } cout << endl; } } void Graph::breadthFirstTraverse(string sourceVertex){ vertex* start = nullptr; for(int i=0;i<vertices.size();i++){ if(vertices[i]->name == sourceVertex){ start = vertices[i]; } } start->visited = true; start->distance = 0; queue<vertex*> q; q.push(start); cout << "Starting vertex (root): " << start->name << "-> "; while(!q.empty()){ vertex* n = q.front(); q.pop(); for(int i=0;i<n->adj.size();i++){ if(!n->adj[i].v->visited){ n->adj[i].v->visited = true; [Show More]

Last updated: 3 years ago

Preview 1 out of 2 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of University of Colorado, Boulder - CSCI 2270Graph.cpp document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$28.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

75
0

Document information


Connected school, study & course


About the document


Uploaded On

Apr 11, 2021

Number of pages

2

Written in

All

Seller


Profile illustration for proff JAY
proff JAY

Member since 4 years

30 Documents Sold

Reviews Received
8
0
0
0
0
Additional information

This document has been written for:

Uploaded

Apr 11, 2021

Downloads

 0

Views

 75

Document Keyword Tags


$28.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·