I have some difficulties to implement one iterative function for sorted insert in linked list. I have previously done that with recursion which is much easier when the insert() function is called, but here I am a bit confused with how to implement the (l->data < data) condition:
insert(List & l, int data){
if (l == 0 || l->data > data){
List new_list = new E_Type;
new_list->data = data;
new_list->next = l;
l = new_list;
}
elseif (l->data < data){
List new_list = new E_Type;
new_list->data = data;
new_list->next = l; //i am shooting in the dark with this one
l = new_list;
}
}