Comparing and Changing Duplicate Values in 2D Array

I am using the following code to check if the first two values in any row of my mx4 array are equal, and if so, to change the value of the 'duplicate' row. Right now, this is showing true for all of the compares and is changing all of my values in the array (sometimes creating duplicates in the process). Any help or suggestions would be appreciated! Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
             
// Check for duplicate arcs
             for (int i=0; i<(m-1); i++)
             {
                 for (int j=1; j<m; j++)
                 {
                     if ((ForwardStar[i][0]==ForwardStar[j][0])&&(ForwardStar[i][1]==ForwardStar[j][1]))
                     {
                        ForwardStar[j][0] = (rand()%(n-1))+1;
                        ForwardStar[j][1] = (rand()%(n-1))+1;
                     }
                 }
             }

Let me know if I should include the rest of the code in the program. I was hoping there was a simple error with the above segment of coding.

Also, after I do change the 'duplicate' row with random numbers, I was thinking I should start the whole duplicate check process over again. I know it's not recommended, but is this a case where I could use the goto function?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Check for duplicate arcs
             CheckForDuplicates:
             for (int i=0; i<(m-1); i++)
             {
                 for (int j=1; j<m; j++)
                 {
                     if ((ForwardStar[i][0]==ForwardStar[j][0])&&(ForwardStar[i][1]==ForwardStar[j][1]))
                     {
                        ForwardStar[j][0] = (rand()%(n-1))+1
                        ForwardStar[j][1] = (rand()%(n-1))+1;
                        Goto CheckForDuplicates;
                     }
                 }
             }
Okay, basic mistake was that in each of my loops, i will equal j, so the AND statement would be true during each loop and change all of my values. I just added a continue statement if (i==j) continue; and this solved that problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
// Check for duplicate arcs
             for (int i=0; i<(m-1); i++)
             {
                 for (int j=1; j<m; j++)
                 {
                     if (i==j) continue;
                     if ((ForwardStar[i][0]==ForwardStar[j][0])&&(ForwardStar[i][1]==ForwardStar[j][1]))
                     {
                        ForwardStar[j][0] = (rand()%(n-1))+1;
                        ForwardStar[j][1] = (rand()%(n-1))+1;
                     }
                 }
             }


Now I just want to make sure my random numbers aren't creating a new duplicate. Would someone recommend another way other than the goto statement?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Check for duplicate arcs
             CheckForDuplicates:
             for (int i=0; i<(m-1); i++)
             {
                 for (int j=1; j<m; j++)
                 {
                     if (i==j) continue;
                     if ((ForwardStar[i][0]==ForwardStar[j][0])&&(ForwardStar[i][1]==ForwardStar[j][1]))
                     {
                        ForwardStar[j][0] = (rand()%(n-1))+1;
                        ForwardStar[j][1] = (rand()%(n-1))+1;
                        goto CheckForDuplicates;
                     }
                 }
             }
Topic archived. No new replies allowed.