my add before current method is not working in the else part .It works when the iterator in the list is at the end but not when its not .Can anyone spot the problem with a little snippet of the code
Code:
list then add item to end of list */
void list_add_before_current(struct listset * p,char item){
struct node * temp = (struct node*)malloc(sizeof (*temp));
if(list_at_end(p)){
temp->next=NULL;
p->tail->next=temp;
temp->key=item;
temp->previous=p->tail;
p->tail=temp;
}
else
{
temp->key=item;
p->iterator->previous->next=temp; //pointing my former previous node next to my new node
temp->next=p->iterator;
p->iterator->previous=temp; //iterator previous now points to my new nod
temp->previous = p->iterator->previous; // new node previous points tom my currents iterator previous
temp->next = p->iterator; //new node next points to my iterator
}
}
int main(int argc, char** argv) {
struct listset *src1;
src1=listset_new();
listset_add(src1, 3);
listset_add(src1, 15);
listset_add(src1, 21);
listset_add(src1, 11);
list_add_before_current(src1,5);