-1
I’m having trouble making a function that receives two lists and returns a third with the elements of the first concatenated with the elements of the second. I made the code but it returns me the third list with the elements of the first and with memory garbage instead of the elements of the second.
Lista concatenar(Lista lst1, Lista lst2) {
Lista lst3 = (Lista) malloc(sizeof(Lista));
int i,j;
for (i = 0; i < lst1->fim; i++) {
lst3->no[i] = lst1->no[i];
}
j = lst3->fim;
for (i = 0; i < lst2->fim; i++) {
lst3->no[j+1] = lst2->no[i];
}
return lst3;
}
Call the inserts(this function is working normal):
insere_elem(lst1, 4);
insere_elem(lst1, 12);
insere_elem(lst1, 0);
insere_elem(lst2, 11);
insere_elem(lst2, 18);
insere_elem(lst2, 25);
Struct lista:
struct lista {
int no[max];
int fim;
};
Post the declaration of your List variable. You say it’s a sequential static list but the treatment gives the impression of being a dynamic chained list.
– anonimo
I did that, added struct to my code
– John Cunha
first you need to make this program compile...because the way you put it just doesn’t compile...
– zentrunix
You are not using linked list, but rather an array. Why do you call this contiguous region of list memory?
– Jefferson Quesado