Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to write a function called translate that moves a sequence in 2d array. This is based off of tsp simulated annealing. I am fairly new to c++ so my code may be terrible.
 double A[][2] = { {0,0}, {1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}, {7,7} };
                           ^dst                         A      B      C
 * call translate( A, 8, 5, 3, 1 ):
 * after:          { {0,0}, {5,5}, {6,6}, {7,7}, {1,1}, {2,2}, {3,3}, {4,4} };
 *                            A      B     C                                  

* @param A is the list of locations (x,y) of the cities in the current tour.
 * @param n is the number of cities in A.
 * @param src is the index of the beginning of the section to be translated (moved).
 * @param len is the length of the segment to translate.
 * @param dst is the index of the beginning of the target of moving.
 */
void translate ( double A[][2], int n, int src, int len, int dst ) {

    //todo: add your code here

}


What I have tried:

I have tried to use a queue

void translate(double A[][2], int city, int source, int length, int destination) {
        double *pointer;
        queue<int> city;
        for (int i = src; i < src + len; src++) {
            q.push(i);
            while (len < n) {
                q.push(i);
            }
        }
Posted
Updated 23-Apr-21 15:09pm

1 solution

This is your homework, so you're not going to be getting a direct answer or piece of code.

I'll give you a couple hints.

In your code snippet, what is q? You never defined it in your code, but yet you're using it like it queue object. This is going to generate a bunch of errors at compile time.

You never use the pointer you defined.

You never use the city you defined. Actually, you defined a variable called 'city', that matches the variable in your argument list you called 'city'. This is going to throw a bunch of errors at compile time.

You also never copy or move any data in the array that's passed in.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900