for the bigraph maximum matching algorithm, I used 2 hash table(unordered_map)to solve it, but when I compiling my code, IDE told me C2100, I even don't know where my code is false, it just happened in the "xhash" document, and I think this problem is associated with iterator. Anyway, please help me to figure out this question, Thanks !
#include<iostream>
#include<queue>
#include<unordered_map>
#include<vector>
using namespace std;
struct Edge
{
int to;
int go;
int length;
Edge* next;
int ID;
};
struct Dot
{
int data;
Edge* first;
};
class Web
{
public:
Web(int num);
~Web();
void Insert(int i, int j, int w);
void DFS(int s, int* visited,queue<int>&);
void BFS(int s, int* visited);
void show()
{
for (int i = 0; i<n; i++)
{
Edge* p = D[i].first;
if (p != NULL)
{
cout << p->length << " ";
p = p->next;
}
}
}
void MostMatch();
private:
int e;
int n;
Dot* D;
vector<Edge*> E;
};
Web::Web(int num)
{
e = 0;
n = num;
D = new Dot[num];
for (int i = 0; i<num; i++)
{
D[i].first = NULL;
D[i].data = 0;
}
}
Web::~Web()
{
delete[] D;
}
void Web::Insert(int i, int j, int w)
{
Edge* p = D[i].first;
int count = 0;
if (D[i].first == NULL)
{
D[i].first = new Edge;
D[i].first->next = NULL;
D[i].first->length = w;
D[i].first->to = j;
D[i].first->go = i;
D[i].first->ID = count++;
E.push_back(D[i].first);
}
else
{
while (p->next != NULL)
p = p->next;
Edge* q = new Edge;
p->next = q;
q->next = NULL;
q->length = w;
q->go = i;
q->to = j;
q->ID = count++;
E.push_back(q);
}
p = D[j].first;
if (D[j].first == NULL)
{
D[j].first = new Edge;
D[j].first->next = NULL;
D[j].first->length = w;
D[j].first->to = i;
D[j].first->ID = count;
e++;
}
else
{
while (p->next != NULL)
p = p->next;
Edge* q = new Edge;
p->next = q;
q->next = NULL;
q->length = w;
q->to = i;
q->ID = count;
e++;
}
}
void Web::MostMatch()
{
cout << "make sure it is a biggraph, press Q to quit." << endl;
char ch;
cin >> ch;
if (ch == 'Q')
{}
else
{
unordered_map<int, int> mape;
unordered_map<int, int> mapd;
int count = 0;
for (int i = 0; i < n; i++)
{
Edge* p;
if (D[i].first)
{
p = D[i].first;
if (mapd.find(i) == mapd.end())
{
while (p)
{
if (mapd.find(p->to) == mapd.end())
{
mapd.insert(i,count++);
mapd.insert(p->to, count++);
mape.insert(p->ID, i);
break;
}
}
}
}
}
unordered_map<int, int>::iterator iter = mape.begin();
while (iter != mape.end())
{
Edge* p = D[E[iter->first]->go].first, *q = D[E[iter->first]->to].first;
while (p)
{
if (mapd.find(p->to) == mapd.end())
{
while (q)
{
if (mapd.find(q->to) == mapd.end())
{
mapd.insert(p->to, count++);
mapd.insert(q->to, count++);
mape.insert(p->ID, count++);
mape.insert(q->ID, count++);
mape.erase(iter->first);
break;
}
}
break;
}
}
iter++;
}
for (iter = mape.begin(); iter != mape.end(); iter++)
{
cout << "v" << E[iter->first]->go << " to v" << E[iter->first]->to << " ID: " << E[iter->first]->ID << endl;
}
}
}
int main()
{
Web w1(8);
w1.Insert(0, 3, 1);
w1.Insert(1, 4, 1);
w1.Insert(1, 5, 1);
w1.Insert(2, 5, 1);
w1.Insert(2, 6, 1);
w1.Insert(2, 7, 1);
w1.Insert(3, 7, 1);
w1.MostMatch();
return 0;
}
I even don't know where my code is false
This is a good reason to minimize your code: https://stackoverflow.com/help/mcve
If your compiler doesn't tell you the error message/line (and, I think, it actually does), try a different one, there is a high chance they are compatible. This one: https://www.onlinegdb.com/online_c++_compiler tells me that lines
mapd.insert(i,count++);
and similar are wrong. Replacing them in the following way compiles:
mapd[i] = count++;
Related
#include <iostream>
#include <list>
using namespace std;
const int TABLESIZE = 3;
class HashTable
{
public:
string k;
int v;
HashTable* next;
HashTable(string k, int v)
{
this->k = k;
this->v = v;
next = NULL;
}
};
class HashMapTable
{
private:
HashTable **t;
public:
HashMapTable()
{
t = new HashTable * [TABLESIZE];
for (int i = 0; i < TABLESIZE; i++)
{
t[i] = NULL;
}
}
int HashFunction(int v)
{
return v % TABLESIZE;
}
void Insert(string k, int v)
{
int hV = HashFunction(v);
HashTable* p = NULL;
HashTable* en = t[hV];
while (en!= NULL)
{
p = en;
en = en->next;
}
if (en == NULL)
{
en = new HashTable(k, v);
if (p == NULL)
{
t[hV] = en;
} else
{
p->next = en;
}
} else
{
en->v = v;
}
}
void PrintTable()
{
for (int i = 0; i < TABLESIZE; i++)
{
if(t[i] != NULL)
{
cout << t[i]->k << " " << t[i]->v << endl;
}
}
}
~HashMapTable()
{
for (int i = 0; i < TABLESIZE; i++)
{
if (t[i] != NULL)
delete t[i];
delete[] t;
}
}
};
int main()
{
HashMapTable HT;
cout << "entering the pairs now" << endl;
HT.Insert("Boramir", 25);
HT.Insert("Legolas", 101);
HT.Insert("Gandalf", 49);
cout << "printing the pairs now" << endl;
HT.PrintTable();
}
My issue is that not all the key value pairs in the table are being printed depending on the table size. If it's 3 (the desired amount) only 2 print, but if it's at least 7, they all print? I'm not sure what piece of my code is causing this to happen. Also, if there are multiple pairs in one bucket, the second/third/etc pair doesn't print and I'm not sure why. Thanks for any help.
Everything works fine apart from the array that's supposed to remember the connected nodes for each node, although it counts only some of them and I'm not sure why. I believe the problem is here:
if (G->v[j] != NULL || G->v[i] != NULL)
However, I'm not sure how to change it.
#include <iostream>
#include <time.h>
#include <list>
#include <iterator>
#include <stack>
#include <queue>
#include "Profiler.h"
using namespace std;
# define MAX_SIZE 20
class Node
{
public:
int key;
int colour; // -1 not visited(white), 0 under visit(gray), 1 visited(black)
Node* p;
int d, f;
list<Node*> adj;
};
Node* newNode(int key) //constructor
{
Node* node = new Node();
node->key = key;
node->colour = -1; // white, not visited
node->d = 0;
node->f = 0;
node->p = NULL;
return node;
}
class Edge
{
public:
Node *v1,*v2;
};
Edge* newEdge(Node* u, Node* v)
{
Edge* edge = new Edge();
edge->v1 = u;
edge->v2 = v;
return edge;
}
class Graph
{
public:
Node* v[MAX_SIZE];
list<Edge*> e;
};
Graph* newGraph(int nb_of_vertices, int nb_of_edges)
{
Graph* G = new Graph();
int i, j;
for (i = 0; i < nb_of_vertices; i++)
{
G->v[i] = NULL;
}
for (i = 0; i < nb_of_vertices; i++)
{
Node* v1 = newNode(i);
G->v[i] = v1;
do
j = rand() % (nb_of_vertices-1);
while (j == i);
if (G->v[j] != NULL || G->v[i] != NULL)
{
Node* v2 = newNode(j);
G->v[j] = v2;
G->v[i]->adj.push_back(v2);
Edge* edge = newEdge(v1, v2);
G->e.push_back(edge);
}
}
return G;
}
void printGraph(Graph* G, int n)
{
list <Node*> ::iterator it;
for (int i = 0; i < n; i++)
{
cout << G->v[i]->key << '\t' << G->v[i]->colour << '\t' << G->v[i]->d << '\t' << G->v[i]->f << '\t';// << G->v[i]->p << '\t';
for (it = G->v[i]->adj.begin(); it != G->v[i]->adj.end(); ++it)
{
cout << (*it)->key << ' ';
}
cout << '\n';
}
list <Edge*> ::iterator it2;
for (it2 = G->e.begin(); it2 != G->e.end(); ++it2)
{
cout << (*it2)->v1->key << "-" << (*it2)->v2->key << ' ';
}
cout << '\n';
}
queue <Node*> solution;
stack <Node*> topsort;
int no_cycle = 1;
void DFSvisit(Graph* G, Node* v, int& time)
{
Node* node = newNode(0);
time++;
v->d = time;
v->colour = 0;
while (!v->adj.empty())
{
node = v->adj.front();
v->adj.pop_front();
if (v->colour == 0)
no_cycle = 0;
if (node->colour == -1)
{
node->p = v;
DFSvisit(G, node, time);
}
}
v->colour = 1;
time++;
v->f = time;
solution.push(v);
topsort.push(v);
}
void DFS(Graph* G, int n)
{
int time = 0, i;
for (i = 0; i < n; i++)
{
if (G->v[i]->colour == -1)
DFSvisit(G, G->v[i], time);
}
}
int main()
{
srand(time(NULL));
int nb_of_vertices = 10, nb_of_edges = 3;
Graph* G = newGraph(nb_of_vertices, nb_of_edges);
printGraph(G, nb_of_vertices);
DFS(G, nb_of_vertices);
printGraph(G, nb_of_vertices);
// DFS traversal
cout << "\nDFS TRAVERSAL\n";
while (!solution.empty())
{
cout << solution.front()->key << " ";
solution.pop();
}
cout << '\n';
// Tarjan's algorithm
// Topological sort
if (no_cycle)
{
cout << "\nTOPOLOGICAL SORTING\n";
while (!topsort.empty())
{
cout << topsort.top()->key << " ";
topsort.pop();
}
}
else
cout << "\nImpossible to perform topological sort, the generated graph contains cycles.\n";
return 0;
}
I'm trying to backtrack through a linkedlist I have created to solve a knight's tour problem, but once I hit a condition requiring me to backtrack, it totally empties the list. I have figured out it is because when I return false from the function findpath() to keep my while loop going, it continually loops back through the goback() function. What I'm having trouble figuring out is why. When i go through the goback function and call the calcmove function, it pushes the correct move to the structure I have declared, so passing false should keep the loop going and restart with the boolean cando and figuring out if that is false or not. But, it should be true because I just tested it and pushed it to the stack. Instead, it's emptying the list after I backtrack for the first time. So calcmove() would just be returning false every time after the first pop. But I don't see why that's happening. I need to return false to keep the loop going. What I need it to do is go back only once, find a new move, and continue on. Why would it be looping back to the function where the value on the list gets popped? If the value worked, and a new move is created (which I did verify it is doing correctly), it should be ready to call with a new (true) boolean. Is this just an inherently bad way of implementing the backtracking?
#include "stdafx.h"
#include "Header.h"
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
llist list;
Move m;
int board[8][8];
int cx[] = { -2, -1, 1, 2, 2, 1, -2, -1 };
int cy[] = { 1, 2, 2, 1, -1, -2, -1, -2 };
int movenum = 1;
Move first;
/*Check to see if move is within the constraints of the board*/
bool constraints(int k, int b) {
if ((k < 0) || (b < 0) || (k > 7) || (b > 7) || (board[k][b] != -1)) {
return true;
}
else {
return false;
}
}
/* Initialization of 8x8 board, fill the array with -1 */
void initboard() {
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
board[x][y] = -1;
}
}
}
/* Output the current board array */
void printboard(int arr[8][8]) {
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
cout << std::setw(2) << arr[x][y] << " ";
}
cout << endl;
}
}
void updateboard(int k, int b) {
board[k][b] = movenum;
movenum++;
}
bool calcmove(int x, int y, int i) {
for (i; i < 9; i++) {
int a0 = x + cx[i];
int a1 = y + cy[i];
/*if(board[a0][a1] == board[first.x][first.y]){
}*/
if (constraints(a0, a1) == false) {
updateboard(a0, a1);
m.x = a0;
m.y = a1;
m.index = i;
list.push(m);
//list.display();
return true;
}
}
return false;
}
void goback(int k, int b) {
board[k][b] = -1;
list.display();
Move m = list.pop();
bool cando = calcmove(m.x, m.y, m.index);
cout << "prev is " << m.x << " , " << m.y << endl;
if (cando) {
return;
}
else {
goback(m.x,m.y);
}
}
bool findpath(){
bool cando = calcmove(m.x, m.y, 0);
if (cando) {
return false;
}
else {
movenum--;
goback(m.x, m.y);
return false; /*------> inserting this here drains the list*/
}
return true;
}
int main()
{
int m1 = 1;
int m2 = 2; //random
first.x = m1;
first.y = m2;
first.index = 0;
list.push(first); //push first node on to stack
initboard();
updateboard(m1, m2); //update board
while (!findpath()) {
;
}
printboard(board);
}
the .h file:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include <ostream>
using std::cout;
using std::endl;
using std::setw;
struct Move {
int x;
int y;
uint32_t index;
};
struct node
{
public:
Move info;
struct node *next;
};
class llist {
struct node *start;
public:
void push(Move coords) {
struct node *p = new node;
p = newnode(coords);
if (start == NULL) {
start = p;
}
else {
p->next = start;
start = p;
//cout << "pushed" << endl;
}
}
Move pop() {
if (start == NULL) {
throw std::runtime_error("The list is empty");
}
else {
struct node *temp = new node;
temp = start;
Move data = start->info;
start = start->next;
delete temp;
//cout << "pop successful" << endl;
return data;
}
}
node *newnode(Move value) {
struct node *temp = new(struct node);
if (temp == NULL) {
return 0;
}
else {
temp->info = value;
temp->next = NULL;
return temp;
}
}
void display()
{
struct node *temp;
if (start == NULL)
{
cout << "The List is Empty" << endl;
return;
}
temp = start;
cout << "Elements of list are: " << endl;
while (temp != NULL)
{
cout << temp->info.x << "->";
temp = temp->next;
}
cout << "empty" << endl;
}
};
The goal of this is to create a linked list, solve the problem using the list for backtracking (push the current move unless no moves are available, then pop the previous values), and return the completed board.
I have a little problem with dijkstra print path, it's working on small graph size like 10-20 etc. On 100 there is problem, because printing loop going to infinity, when I've tried recurrence method, VS is showing me exepction throw, stack overflow (same problem like up ^). Do u know guys how to repair it ? There is my code.
#include <stdio.h>
#include <iostream>
#include <limits.h>
#include <conio.h>
using namespace std;
struct graphNode {
int weight;
int v;
graphNode *next;
};
class Graph {
public:
graphNode *head, *tail;
int size, vIndex;
int currentWeight;
char type;
void addNode(int v_temp, int v_weight) {
graphNode *temp = new graphNode;
temp->next = nullptr;
if (head == nullptr) {
temp->v = v_temp;
temp->weight = v_weight;
head = temp;
}
else {
tail->next = temp;
temp->v = v_temp;
temp->weight = v_weight;
}
size++;
tail = temp;
}
// GET SET METHODS
char returnType() {
return type;
}
int returnCurrentWeight() {
return currentWeight;
}
void setCurrentWeight(int weight) {
currentWeight = weight;
}
void setVIndex(int temp) {
vIndex = temp;
}
void setType(char type_temp) {
type = type_temp;
}
// Constructor
Graph() {
head = nullptr;
tail = nullptr;
vIndex = 0;
size = 0;
currentWeight = 0;
}
};
struct heapNode {
int v;
int distance;
};
class Heap {
private:
Graph *graphArray;
heapNode **heapArray;
heapNode *root;
int vNumber, size;
int *position, *parent;
public:
heapNode *addEdge(int temp_v, int temp_distance) {
heapNode *temp = new heapNode;
temp->v = temp_v;
temp->distance = temp_distance;
return temp;
}
graphNode *returnVertexHead(int i) {
return graphArray[i].head;
}
char returnType(int i) {
return graphArray[i].returnType();
}
int *returnParent() {
return parent;
}
int returnWeight(int i) {
return graphArray[i].returnCurrentWeight();
}
void setWeight(int i, int weight) {
graphArray[i].setCurrentWeight(weight);
}
bool isInHeap(int temp_v) {
if (position[temp_v] < vNumber) return true;
return false;
}
bool isEmpty(int vNumber) {
if (vNumber == 0) return true;
return false;
}
void decrestDistans(int temp_v, int temp_distance) {
int index = position[temp_v];
heapNode *temp;
heapArray[index]->distance = temp_distance;
while (index && (heapArray[index]->distance < heapArray[(index - 1) / 2]->distance)) {
position[heapArray[index]->v] = (index - 1) / 2;
position[heapArray[(index - 1) / 2]->v] = index;
temp = heapArray[index];
heapArray[index] = heapArray[(index - 1) / 2];
heapArray[(index - 1) / 2] = temp;
index = (index - 1) / 2;
}
}
heapNode *removeMin() {
if (vNumber == 0) return nullptr;
root = heapArray[0];
heapArray[0] = heapArray[vNumber - 1];
position[root->v] = vNumber - 1;
position[heapArray[vNumber - 1]->v] = 0;
--vNumber;
repairHeapDown(0);
return root;
}
void repairHeapDown(int index) {
heapNode *temp;
int parentIndex = index;
int left = index * 2 + 1;
int right = index * 2 + 2;
if (left <= vNumber && heapArray[parentIndex]->distance > heapArray[left]->distance) parentIndex = left;
if (right <= vNumber && heapArray[parentIndex]->distance > heapArray[right]->distance) parentIndex = right;
if (index != parentIndex) {
position[heapArray[parentIndex]->v] = index;
position[heapArray[index]->v] = parentIndex;
temp = heapArray[index];
heapArray[index] = heapArray[parentIndex];
heapArray[parentIndex] = temp;
repairHeapDown(index);
}
}
int dijkstra(int start, int target) {
int *distance = new int[vNumber];
int i, v, weight;
graphNode *current_graph;
heapNode *current_heap;
for (int i = 0; i < vNumber; i++)
{
distance[i] = INT_MAX;
heapArray[i] = addEdge(i, distance[i]);
position[i] = i;
parent[i] = 0;
}
parent[start] = -1;
heapArray[start] = addEdge(start, distance[start]);
position[start] = start;
distance[start] = 0;
decrestDistans(start, distance[start]);
while (!isEmpty(vNumber)) {
current_heap = removeMin();
i = current_heap->v;
if (i == target) {
int temp = 2 * distance[target];
parent[v] = i;
delete[] position;
delete[] distance;
delete[] heapArray;
return temp;
}
current_graph = returnVertexHead(i);
while (current_graph != nullptr) {
v = current_graph->v;
weight = current_graph->weight + returnWeight(i) + distance[i];
if (weight < distance[v]) {
distance[v] = weight;
decrestDistans(v, distance[v]);
parent[v] = i;
}
current_graph = current_graph->next;
}
}
return 0;
}
Heap(Graph *table, int temp_vNumber) {
vNumber = temp_vNumber;
size = temp_vNumber;
root = nullptr;
heapArray = new heapNode*[size];
position = new int[size];
parent = new int[size];
graphArray = table;
}
~Heap() {
delete[] parent;
}
};
void printPath(int *parent, int start, int target)
{
int current = target;
while (current != start) {
cout << current << " ";
current = parent[current];
}
cout << current << " ";
}
int main() {
int n, time_knight, patch_number, temp_v, temp_weight, i,
home_index, gral_index, ni_index, ni_weight, krzak_index;
char type;
gral_index = home_index = ni_index = krzak_index = 0;
i = 0;
cin >> n >> time_knight;
Graph *table = new Graph[n];
while (1) {
cin >> type;
table[i].setType(type);
if (type == '5') gral_index = i;
if (type == '4') home_index = i;
if (type == '3') ni_index = i;
if (type == '2') table[i].setCurrentWeight(time_knight);
if (type == '1') krzak_index = i;
cin >> patch_number;
for (int j = 0; j < patch_number; j++)
{
cin >> temp_v >> temp_weight;
table[i].setVIndex(i);
table[i].addNode(temp_v, temp_weight);
}
i++;
if (i == n) break;
}
Heap *object = new Heap(table, n);
Heap *object2 = new Heap(table, n);
ni_weight = object->dijkstra(ni_index, krzak_index);
table[ni_index].setCurrentWeight(ni_weight);
cout << endl << endl << endl;
printPath(object->returnParent(), ni_index, krzak_index);
cout << endl << endl << endl;
object2->dijkstra(home_index, gral_index);
printPath(object2->returnParent(), home_index, gral_index);
_getch();
return 0;
}
I tried to implement BFS for graphs using link list but i have some issues with it, using a queue it only displays the nodes of that origin and not after it. The answer should be 2031 but i only get 203.
The code is below:
#include <iostream>
#include <cmath>
#include <vector>
#include <stdlib.h>
#include <queue>
using namespace std;
class linkListNode
{
public:
linkListNode *next;
int destination;
bool visited;
linkListNode()
{
next = NULL;
destination =0;
visited=false;
}
};
class linkList
{
public:
linkListNode *head;
linkList()
{
head = NULL;
}
// append type insert
void insert(int value)
{
linkListNode *temp2 = new linkListNode;
temp2->destination = value;
temp2->next = NULL;
linkListNode *nodePtr = new linkListNode;
if (head == NULL)
{
head = temp2;
temp2->next = NULL;
}
else
{
nodePtr = head;
while (nodePtr->next)
{
nodePtr = nodePtr->next;
}
nodePtr->next = temp2;
}
}
void display()
{
linkListNode *temp = new linkListNode;
temp = head;
while (temp)
{
cout << temp->destination << " --> ";
temp = temp->next;
}
cout << endl;
}
int size()
{
linkListNode *temp = head;
int sizer = 0;
while (temp)
{
sizer++;
temp = temp->next;
}
return sizer;
}
};
class edge
{
public:
int origin;
linkList final;
bool visited;
edge()
{
//origin = NULL;
//cost=0;
visited=false;
}
};
class graph
{
private:
vector <edge> vectorOfEdges;
int vertices;
public:
graph(int v)
{
vertices = v;
vectorOfEdges.clear();
}
void addRoute(int ori, int dest)
{
int counter = 0;
for (int i = 0; i<vectorOfEdges.size(); i++)
{
edge e = vectorOfEdges[i];
if (e.origin== ori)
{
counter = 1; // means element was present in the list
e.final.insert(dest);
}
vectorOfEdges[i] = e;
}
if (counter == 0) // when counter is set to zero, this means that the element was not found in the vector and needs to be pushed
{
edge e;
e.origin = ori;
e.final.insert(dest);
vectorOfEdges.push_back(e);
}
}
void printGraph()
{
edge e;
for (int i = 0; i<vectorOfEdges.size(); i++)
{
e = vectorOfEdges[i];
cout << e.origin << ":- ";
e.final.display();
cout << endl;
}
}
int sizeOfEdge(edge e)
{
int x = e.final.size() + 1;
return x;
}
int max(int one, int two)
{
if (one > two)
{
return one;
}
else
{
return two;
}
}
void BFS(int start)
{
edge e;
queue <int> q;
int save_index=0;
for (int i=0;i<vectorOfEdges.size();i++)
{
e=vectorOfEdges[i];
if (e.origin == start)
{
save_index=i;
q.push(e.origin);
e.visited=true;
break;
}
}
while (!q.empty())
{
int x=q.front();
cout << x << " " ;
q.pop();
linkListNode *l = e.final.head;
while (l)
{
if (l->visited == false)
{
q.push(l->destination);
l->visited=true;
l=l->next;
}
else
{
l=l->next;
}
}
}
}
};
int main()
{
graph g(4);
g.addRoute(0, 1);
g.addRoute(0, 2);
g.addRoute(1, 2);
g.addRoute(2, 0);
g.addRoute(2, 3);
// g.printGraph();
//cout << "Following is Breadth First Traversal (starting from vertex 2) \n";
g.BFS(1);
}
Your code is only running for the node that you have provided as the starting value for your BFS traversal.
void BFS(int start)
{
queue<int> q;
bool startFound = false;
for (int i = 0; i < vectorOfEdges.size(); i++)
{
edge e = vectorOfEdges[i];
if (e.origin == start)
{
q.push(e.origin);
check.push_back(e.origin);
e.visited = true;
startFound = true;
break;
}
}
if (!startFound)
{
cout << "Start vertex not found in the graph" << endl;
return;
}
while (!q.empty())
{
int x = q.front();
cout << x << " ";
q.pop();
for (int i = 0; i < vectorOfEdges.size(); i++)
{
edge e = vectorOfEdges[i];
if (e.origin == x)
{
linkListNode *l = e.final.head;
while (l != NULL)
{
bool found = false;
if (l->visited == false)
{
l->visited = true;
for (int i = 0; i < check.size(); i++)
{
if (check[i] == l->destination)
{
found = true;
break;
}
}
if (found == false)
{
check.push_back(l->destination);
q.push(l->destination);
}
}
l = l->next;
}
}
}
}
}
Instead, do this to run it for every node.