Hello,
The program finds the shortest path between the user inputted nodes. The nodes are integer. Now I need to modify my code to find the path between nodes which are string.
Path between A and B instead of 1 and 2. Please help me to convert my code.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
struct node {
int info;
node *next;
};
class Queue
{
public:
Queue();
~Queue();
bool isEmpty();
void add(int);
int get();
private:
node *first, *last;
};
class Graph {
public:
Graph(int size = 2);
~Graph();
bool isConnected(int, int);
// adds the (x, y) pair to the edge set
void addEdge(int x, int y);
// performs a Breadth First Search starting with node x
void BFS(int x);
// searches for the minimum length path
// between the start and target vertices
void minPath(int start, int target);
private :
int n;
int **A;
};
Queue::Queue()
{
first = new node;
first->next = NULL;
last = first;
}
Queue::~Queue()
{
delete first;
}
bool Queue::isEmpty() {
return (first->next == NULL);
}
void Queue::add(int x)
{
node *aux = new node;
aux->info = x;
aux->next = NULL;
last->next = aux;
last = aux;
}
int Queue::get()
{
node *aux = first->next;
int value = aux->info;
first->next = aux->next;
if (last == aux) last = first;
delete aux;
return value;
}
Graph::Graph(int size)
{
int i, j;
if (size < 2) n = 2;
else n = size;
A = new …