RE: g_list_first()



Hello, What did you need to do exactly????

If you need to test all elements in a single list and delete elements you whish you can use this type of code, it isn't optimised but it work's, else you can use g_list_foreach to apply a personnal function at each element of your GSList but it doesn't work for deleting GSList.
If you need any explanation mail me.

static GSList* _your_function(GSList* list, gint X)
{
GSList *saveList=list,*buflist=list;

while(list)
{
     if(  your_test  )  //(list->data < X) for example
     {
	    gfree(list->data);

if(list==buflist) // case of first element of the list, we don't loose the begin of the list
	    {
	        saveList=list->next;
	        buflist=list->next;
               gfree(list);
               list=buflist;
	    }
	    else
	    {
buflist->next=list->next; //if you need to free the list, update the next element of the preceding list
               gfree(list);

               list=buflist->next;
	    }
     }
     else
     {
           buflist=list;
	    list=list->next;
     }
}

return saveList;
}





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]