ana aly

ana aly

  • NA
  • 22
  • 0

how do i write this for vb.net

Sep 20 2007 1:18 AM
hi. i am translating c code to vb.net code. i am new with this language. basically i had translate it without any error but it doesnt work as what i want. can anyone help me with this.i got this code from a book i read.

#include <stdio.h>
#define VERTEXNUM 4
#define HUGE 32000

const char *vertices [] ={
    "selandar",
    "chinchin",
    "jasin",
    "merlimau"
};

const int edges [VERTEXNUM][VERTEXNUM] ={
    {0,22,16,32},
    {22,0,15,26},
    {16,15,0,21},
    {32,26,21,0}
};

int visited [VERTEXNUM] ={0};
int curMinCost = HUGE;

int curMinHamNum = 0;
int currentRoute [VERTEXNUM];

void findRoute (int start, int current, int costSoFar, int numVisited);
void foundHamiltonian (int start, int cost);

int main (void) {
    int start = 0;
    int j;
    for (j=0; j<VERTEXNUM; j++)
        if (j != start) findRoute (start, j, edges [start][j],0);
        printf("lowest cost hamiltonian cycle: %d w/ cost %d\n", curMinHamNum,
                 curMinCost);
                 getchar();
                 return (0);
            }

void findRoute (int start, int current, int costSoFar, int numVisited) {
    int j;
    currentRoute[numVisited]=current;
   
    if (current == start) {
        if (numVisited == VERTEXNUM -1)
                foundHamiltonian (start, costSoFar+edges[current][start]);
            } else {
                visited[current] = 1;
                for (j=0; j<VERTEXNUM; j++) {
                    if (!visited[j])
                    findRoute(start,j,costSoFar+edges[current] [j], numVisited+1);
                }
               
                 visited[current] = 0;
             }
         }
        
    
 void foundHamiltonian (int start, int cost) {
     int j;
     static int hamNum=0;
     hamNum++;
     printf("#%d: %s", hamNum, vertices[start]);
     for (j=0; j<VERTEXNUM; j++)
          printf ("->%s", vertices[currentRoute[j]]);
     printf ("costs %d\n", cost);
        
      if (cost < curMinCost){
          curMinCost =cost;
          curMinHamNum = hamNum;
         }
     }                     

Answers (17)