Modify caller array instead of copy
This commit is contained in:
parent
a5c402bc84
commit
52b5f0e361
28
generator.c
28
generator.c
@ -200,7 +200,7 @@ int findIndex(int array[], int value, int size)
|
|||||||
return (index == size ? -1 : index);
|
return (index == size ? -1 : index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void genSolution(int permutation[], int V)
|
void genSolution(int permutation[], int V, int *solution)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -218,8 +218,10 @@ void genSolution(int permutation[], int V)
|
|||||||
permutation[i] = tmp;
|
permutation[i] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int edges[MAX_ITEMS] = {-1};
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
for (int i = 0; i < MAX_ITEMS; i++) {
|
||||||
|
solution[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
for (int u = 0; u < V; u++) {
|
for (int u = 0; u < V; u++) {
|
||||||
int idx = findIndex(permutation, u, V);
|
int idx = findIndex(permutation, u, V);
|
||||||
@ -227,8 +229,8 @@ void genSolution(int permutation[], int V)
|
|||||||
while (pCrawl) {
|
while (pCrawl) {
|
||||||
int idx_v = findIndex(permutation, pCrawl->dest, V);
|
int idx_v = findIndex(permutation, pCrawl->dest, V);
|
||||||
if (idx > idx_v) {
|
if (idx > idx_v) {
|
||||||
edges[count++] = u;
|
solution[count++] = u;
|
||||||
edges[count++] = pCrawl->dest;
|
solution[count++] = pCrawl->dest;
|
||||||
if (count > MAX_ITEMS)
|
if (count > MAX_ITEMS)
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
@ -237,11 +239,13 @@ void genSolution(int permutation[], int V)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
printf("[");
|
printf("[");
|
||||||
for (int i = 0; i < (count - 1); i++) {
|
for (int i = 0; i < (count - 1); i++) {
|
||||||
printf("%d, ", edges[i]);
|
printf("%d, ", solution[i]);
|
||||||
}
|
}
|
||||||
printf("%d]\n", edges[count-1]);
|
printf("%d]\n", solution[count-1]);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@ -287,7 +291,17 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
while (quit == 0) {
|
while (quit == 0) {
|
||||||
for (int i = 0; i < 1000000; i++) {
|
for (int i = 0; i < 1000000; i++) {
|
||||||
genSolution(permutation, graph.V);
|
int solution[MAX_ITEMS];
|
||||||
|
genSolution(permutation, graph.V, solution);
|
||||||
|
printf("[");
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < (MAX_ITEMS - 2); j++) {
|
||||||
|
if (solution[j+1] != -1)
|
||||||
|
printf("%d, ", solution[j]);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("%d]\n", solution[j]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user