Re: g_list_first()

On Mo, 2005-11-28 at 15:24 -0400, Elmano Carvalho wrote:
> Hello, 
> I am writing an application that uses Singly-Linked Lists for adding
> and removing elements on that list. 
> I need to go through the list, identify each element and remove them
> on the go...
> As the subject suggests, there's a function for getting the first
> element of the list (g_list_first()), which is what I need, but is 
> only available for the doubly-linked lists implementations... 
> However, there's one, namely g_slist_nth(),  which should do the trick
> but on the iteration it fails to get the elements, so I can
> do what I want with them. 
> Am I on the right track, or is there another function in glib.h that
> would work like a charm for the GSList?


like the name says the list ist only linked in one way, so there is no
reference from one element to the previous.

One way is to hold a reference to the first element of the list (you
always shall do it, cause otherwise you later cant free em later) and
from there use g_slist_nth.

Else use the double linked list. In most cases the overhead is not that


Ps. This list is for the development of Gtk+ self. Please post this kind
of questions to the gtk-app-devel list.

> Thanks in advance for the pointers, 
> Elmano Carvalho
> elmano carvalho gmail com
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org

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