Skip to content

Commit a65fda3

Browse files
authored
update TSP.cpp
Added documentation for easy understanding of the code
1 parent 0346894 commit a65fda3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Travelling Salesman Problem/C++/Travelling Salesman Problem.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ void takeInput()
99
{
1010
int i,j;
1111

12-
cout<<"Enter the number of villages: ";
13-
cin>>n;
12+
cout<<"Enter the number of villages: "; //Take input for number of destinations to be visited
13+
cin>>n;
1414

15-
cout<<"\nEnter the Cost Matrix\n";
15+
cout<<"\nEnter the Cost Matrix\n"; //input of the cost matrix
1616

1717
for(i=0;i < n;i++)
1818
{
@@ -26,15 +26,15 @@ void takeInput()
2626

2727
cout<<"\n\nThe cost list is:";
2828

29-
for( i=0;i < n;i++)
29+
for( i=0;i < n;i++) //Calculates the cost list for the matrix
3030
{
3131
cout<<"\n";
3232

3333
for(j=0;j < n;j++)
3434
cout<<"\t"<<ary[i][j];
3535
}
3636
}
37-
37+
//Computes the least cost and returns the value
3838
int least(int c)
3939
{
4040
int i,nc=999;
@@ -56,7 +56,7 @@ int least(int c)
5656

5757
return nc;
5858
}
59-
59+
//Provides min cost for a city
6060
void mincost(int city)
6161
{
6262
int i,ncity;
@@ -77,7 +77,7 @@ void mincost(int city)
7777

7878
mincost(ncity);
7979
}
80-
80+
//Driver code for the above functions
8181
int main()
8282
{
8383
takeInput();
@@ -88,4 +88,4 @@ int main()
8888
cout<<"\n\nMinimum cost is "<<cost;
8989

9090
return 0;
91-
}
91+
}

0 commit comments

Comments
 (0)