Me again, this time I really have a problem.
I'm trying to add an element before a certain element.
Example:
List: 1,2,3,4,5
Find: 2
Add: 45
List: 1,45,2,3,4,5
Now the thing is that when I find the number and try to add a new number it adds OK but then it deletes the last element of the list.
Example:
List: 1,2,3,4,5
Find: 2
Add: 45
List: 1,45,2,3,4
How do I fix this? This is my code below:
node* p_before = find_element(number, k_beginning); //return a pointer to an element we're trying to find
node* p_after = p_before->k_next;
node* k_new= new node;
k_new->number= number;
k_new->k_next= k_after;
p_before->k_next= k_new;