Hi,I am implementing graph ,all function works except the Hamiltonian part(1 function and 2 private method).Every time i compile,it shows two error message,,i don't know how to use adjacency list or is there any way to implement it using the class declaration as given above...I have main problem on my pathok function (those two returning statements..)

my code is:

``````#include <iostream>
#include <vector>
#include <queue>

template <typename ItemType>
class Graph          //CLASS DECLARATION
{
public:

bool Hamilton(vector<int>& x);

private:

class VertexNode;
typedef VertexNode * NodePointer;

class VertexNode
{
public:
VertexNode(int n) { vert = n; next = 0; }

int vert;
NodePointer next;
};

vector<ItemType> vertex;

vector<bool> visit;

bool RecursHamilton(int k, vector<int>& x);

bool PathOK(int k, const vector<int>& x);
};

template <typename ItemType>
bool Graph<ItemType>::RecursHamilton(int k, vector<int>& x)
{
int j;
vector<bool> used;
for( x[k] = 2;x[k] < x[n];x[k]++)
if(PathOK(j,x))
{
used[x[k]] = true;
if(k == n || RecursHamilton(j,x))
return true;
used[x[k]] = false;
}
return false;

}

template <typename ItemType>
bool Graph<ItemType>::PathOK(int k, const vector<int>& x)
{
vector<bool> used;

if(used[x[k]])
return false;

if(k<n)
else

}

template <typename ItemType>
bool Graph<ItemType>::Hamilton(vector<int>& x)
{
vector<bool> used;
int j;
x[0] = 1;
used[0] = true;
for(int i = 2;i<=n;i++)
used[i] = false;
RecursHamilton(j, x);
return false;
}``````
1
Contributor
2
Replies
3
Views
9 Years
Discussion Span
Last Post by prs55

.

.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.