You are on page 1of 2

104 H34019011

This code can be compiled and run ok.


usage:
hw5.cpp : use the recursive function and adjacency matrix to find the Hamiltonian path
input file:
matrix.dat :
compile:
g++ hw5.cpp

pseudocode
int promising (int i, int **a, int *visit, int length){
isPromising is true;
If the last and the first point dont connect, then set isPromising is false;
Else if the i and the (i-1) node dont connect, then set isPromising is false;
Else if i node has appeared before, then set isPromising is false;
return isPromising;
}

void hamiltonian (int i, int **a, int *visit, int length){
If the i node has the previous node in the path{
Base case:
if i is the last index in array, then print the all possible path;
General case:
Else let all nodes expect the first node become the next node, and call the recursive function;
}
}

int main(){
Input the matrix.dat this file into the program;
Set a two-dimension dynamic array, and store the value into array;
Set the first node is A;
Call the recursive function, hamiltonian();
Delete a two-dimension dynamic array, release the memory space;
}


104 H34019011
Test Case




coded by Ting-Hui Fang(), ID: H34019011, email: H34019011@mail.ncku.edu.tw
date: 2013.6.3

You might also like