i have been working with this iterative function since Sunday without any success, I want to create iterative function for sorted insert but after hour of node drawings, I think i would need some help with the function:
struct declaration:
typedef struct E_Type * List;
struct E_Type
{
int data;
struct E_Type* next;
};
the function:
bool insert(List & l, int data) {
while (l != 0) {
for (List p = l; p; p = p->next) {
if (p->data == data)
return false;
}
if (l->data > data) {
List new_list = new E_Type;
new_list->data = data;
new_list->next = l;
l = new_list;
return true;
} else if (l->data < data) {
List new_list = new E_Type;
new_list->data = data;
l->next = new_list;
l = new_list;
return true;
}
}
if (l == 0) {
List new_list = new E_Type;
new_list->data = data;
new_list->next = l;
l = new_list;
return true;
}
}
btw: is this function even possible... all tutorials, infos etc about this insertion are with recursive call for next-data