0
I am trying to intermediate the values of two rows in C, F1 and F2, in a third row, inter, as function below (n would be the amount of F1 and F2 elements):
Fila *intercala_fila (Fila *f1, Fila *f2){
int Tam, i;
Fila *Inter = fila_cria();
Tam = f1->n + f2->n;
for(i=0;i<Tam;i++){
fila_insere(Inter, f1->vet[i]);
fila_insere(Inter, f2->vet[i]);
}
return Inter; }
I am successfully interlink, however, I am getting memory junk in the result, as below:
10 //valor de f1
3 //valor de f2
5 //valor de f1
8 //valor de f2
2 //valor de f1
//abaixo são printados os lixos de memória
1297903728
1275095411
1464299113
1279345487
1650209846
How can I get a result where I can intermediate the values of both queues without getting memory values, or else without omitting F1 or F2 values?
Thank you!
But what is the definition of your Fila? At first it does not seem correct to add up the amount of elements of the two rows and try to access such quantity in each of them.
– anonimo
Your for loop goes to Tam (which is the sum of the size of the two rows), but the F1 and F2 rows are smaller than Tam
– G. Bittencourt