I do not know how your function is running endlessly. The impression I have is that if this function gets stuck in an infinite loop it should stop sometime with a stackoverflow error.
Anyway, you might notice some of the wrong things in your implementation.
Let's look at the part where you are deleting the element. Assume we have a list A-> B-> C and you are trying to remove B. You are currently 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 rDelete function and at no time did you change the value of the prox
field of the "A" node in the list.
The simplest way to resolve this problem is to modify the rDeleta
function instead of returning void, returning the pointer to the list head that is obtained by removing the elemento
element from the l
/ p>
I think with this tip maybe you can solve your exercise.