I don’t know how your function is running endlessly. The impression I get is that if this function gets stuck in an infinite loop it should stop at some point with a stackoverflow error.
Anyway, you can see some things wrong in its implementation.
Let’s look at the part where you’re deleting the element. Assume that we have an A->B->C list and you are trying to remove B. Currently you are doing this with a l = l->prox
:
antes:
l ---\
|
v
[ A ] --> [ B ] --> [ C ]
depois de l = l->prox:
l ---\
|
v
[ A ] --> [ B ] --> [ C ]
However, the variable l
is a local variable of the rDeleta function and at no time you changed the value of the field prox
of node "A" of the list.
The simplest way to solve this problem is to modify the function rDeleta
for instead of returning void, return the pointer to the head of the list that is obtained by removing the element elemento
of the list l
.
I think with this tip you might be able to solve your exercise.
previously auterei for list return type and ran.
– tonho