# c – Discussion list problem

I have to make a code that interleaves two lists (already ordered) keeping the order and without repeating the values. I arrived at the following code:

``````#include
#include

struct Cel {
int value;
struct Cel * prox;
};

typedef struct Cel cel;

empty insert (cel ** i, cel ** t, int value) {
cel * temp = malloc (sizeof (cel));
temp-> prox = NULL;
temp-> value = value;

if (* i == NULL) * i = temp;
else (* t) -> prox = temp;

* t = temp;

}

zero interlace (cel * p1, cel * p2, cel ** i, cel ** t) {
cel * temp1 = p1;
cel * temp2 = p2;

while (temp1! = NULL && temp2! = NULL) {
printf ("temp1:% d | temp2:% d | t:% d  n", temp1-> value, temp2-> value, * t> value);
if (temp1-> value < temp2->value && temp1-> value! = (* t) -> value) {
insert (i, t, temp -1> value);
temp1 = temp1-> prox;

} else if (temp2-> value < temp1->value && temp2-> value! = (* t) -> value) {
insert (i, t, temp2-> value);
temp2 = temp2-> prox;
printf ("% d  n", (* t) -> value);
}
}
}

empty print (cel * list) {
for (that is, to = list, to! = NULL, to => prox)
printf ("% d  n", aux-> value);
}

void * insert2 (cel ** list, int x) {
cel * temp = NULL, * to = * list;

temp = malloc (sizeof (cel));
temp-> value = x;
temp-> prox = NULL;

if (* list == NULL)
* list = temp;
if not {
for (; aux-> prox! = NULL; aux = aux-> prox);
aux-> prox = temp;
}
}

int main () {
cel * list1 = NULL;
cel * list2 = NULL;

cel * i = NULL;
cel * t = NULL;

insert2 (& list1, 1);
insert2 (& list1, 2);
insert2 (& list1, 3);
insert2 (& list1, 4);
insert2 (& list1, 4);
insert2 (& list1, 4);
insert2 (& list1, 4);

insert2 (& list2, 1);
insert2 (& list2, 2);
insert2 (& list2, 3);
insert2 (& list2, 4);

interleaving (list1, list2, & i, & t);

print (i);
}
``````

I've already noticed that this poses a problem in the interstitial function when I try to access the pointer pointer value:

``````temp1-> value! = (* t) -> value
``````

already tried to put with and without the parenthesis, without success. No mistake, just leave. if I delete this bit, it works (but does not do what I want)