<refentry id="glib-Doubly-Linked-Lists">
<refmeta>
<refentrytitle>Doubly-Linked Lists</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GLIB Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Doubly-Linked Lists</refname><refpurpose>linked lists containing integer values or pointers to data, with the ability
to iterate over the list in both directions.</refpurpose>
</refnamediv>

<refsynopsisdiv><title>Synopsis</title>
<synopsis>

#include &lt;glib.h&gt;


struct      <link linkend="GList">GList</link>;

<link linkend="GList">GList</link>*      <link linkend="g-list-append">g_list_append</link>                   (<link linkend="GList">GList</link> *list,
                                             <link linkend="gpointer">gpointer</link> data);
<link linkend="GList">GList</link>*      <link linkend="g-list-prepend">g_list_prepend</link>                  (<link linkend="GList">GList</link> *list,
                                             <link linkend="gpointer">gpointer</link> data);
<link linkend="GList">GList</link>*      <link linkend="g-list-insert">g_list_insert</link>                   (<link linkend="GList">GList</link> *list,
                                             <link linkend="gpointer">gpointer</link> data,
                                             <link linkend="gint">gint</link> position);
<link linkend="GList">GList</link>*      <link linkend="g-list-insert-before">g_list_insert_before</link>            (<link linkend="GList">GList</link> *list,
                                             <link linkend="GList">GList</link> *sibling,
                                             <link linkend="gpointer">gpointer</link> data);
<link linkend="GList">GList</link>*      <link linkend="g-list-insert-sorted">g_list_insert_sorted</link>            (<link linkend="GList">GList</link> *list,
                                             <link linkend="gpointer">gpointer</link> data,
                                             <link linkend="GCompareFunc">GCompareFunc</link> func);
<link linkend="GList">GList</link>*      <link linkend="g-list-remove">g_list_remove</link>                   (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data);
<link linkend="GList">GList</link>*      <link linkend="g-list-remove-link">g_list_remove_link</link>              (<link linkend="GList">GList</link> *list,
                                             <link linkend="GList">GList</link> *llink);
<link linkend="GList">GList</link>*      <link linkend="g-list-delete-link">g_list_delete_link</link>              (<link linkend="GList">GList</link> *list,
                                             <link linkend="GList">GList</link> *link);
<link linkend="GList">GList</link>*      <link linkend="g-list-remove-all">g_list_remove_all</link>               (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data);
void        <link linkend="g-list-free">g_list_free</link>                     (<link linkend="GList">GList</link> *list);

<link linkend="GList">GList</link>*      <link linkend="g-list-alloc">g_list_alloc</link>                    (void);
void        <link linkend="g-list-free-1">g_list_free_1</link>                   (<link linkend="GList">GList</link> *list);

<link linkend="guint">guint</link>       <link linkend="g-list-length">g_list_length</link>                   (<link linkend="GList">GList</link> *list);
<link linkend="GList">GList</link>*      <link linkend="g-list-copy">g_list_copy</link>                     (<link linkend="GList">GList</link> *list);
<link linkend="GList">GList</link>*      <link linkend="g-list-reverse">g_list_reverse</link>                  (<link linkend="GList">GList</link> *list);
<link linkend="GList">GList</link>*      <link linkend="g-list-sort">g_list_sort</link>                     (<link linkend="GList">GList</link> *list,
                                             <link linkend="GCompareFunc">GCompareFunc</link> compare_func);
<link linkend="gint">gint</link>        (<link linkend="GCompareFunc">*GCompareFunc</link>)                 (<link linkend="gconstpointer">gconstpointer</link> a,
                                             <link linkend="gconstpointer">gconstpointer</link> b);
<link linkend="GList">GList</link>*      <link linkend="g-list-sort-with-data">g_list_sort_with_data</link>           (<link linkend="GList">GList</link> *list,
                                             <link linkend="GCompareDataFunc">GCompareDataFunc</link> compare_func,
                                             <link linkend="gpointer">gpointer</link> user_data);
<link linkend="gint">gint</link>        (<link linkend="GCompareDataFunc">*GCompareDataFunc</link>)             (<link linkend="gconstpointer">gconstpointer</link> a,
                                             <link linkend="gconstpointer">gconstpointer</link> b,
                                             <link linkend="gpointer">gpointer</link> user_data);
<link linkend="GList">GList</link>*      <link linkend="g-list-concat">g_list_concat</link>                   (<link linkend="GList">GList</link> *list1,
                                             <link linkend="GList">GList</link> *list2);
void        <link linkend="g-list-foreach">g_list_foreach</link>                  (<link linkend="GList">GList</link> *list,
                                             <link linkend="GFunc">GFunc</link> func,
                                             <link linkend="gpointer">gpointer</link> user_data);
void        (<link linkend="GFunc">*GFunc</link>)                        (<link linkend="gpointer">gpointer</link> data,
                                             <link linkend="gpointer">gpointer</link> user_data);

<link linkend="GList">GList</link>*      <link linkend="g-list-first">g_list_first</link>                    (<link linkend="GList">GList</link> *list);
<link linkend="GList">GList</link>*      <link linkend="g-list-last">g_list_last</link>                     (<link linkend="GList">GList</link> *list);
#define     <link linkend="g-list-previous">g_list_previous</link>                 (list)
#define     <link linkend="g-list-next">g_list_next</link>                     (list)
<link linkend="GList">GList</link>*      <link linkend="g-list-nth">g_list_nth</link>                      (<link linkend="GList">GList</link> *list,
                                             <link linkend="guint">guint</link> n);
<link linkend="gpointer">gpointer</link>    <link linkend="g-list-nth-data">g_list_nth_data</link>                 (<link linkend="GList">GList</link> *list,
                                             <link linkend="guint">guint</link> n);
<link linkend="GList">GList</link>*      <link linkend="g-list-nth-prev">g_list_nth_prev</link>                 (<link linkend="GList">GList</link> *list,
                                             <link linkend="guint">guint</link> n);

<link linkend="GList">GList</link>*      <link linkend="g-list-find">g_list_find</link>                     (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data);
<link linkend="GList">GList</link>*      <link linkend="g-list-find-custom">g_list_find_custom</link>              (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data,
                                             <link linkend="GCompareFunc">GCompareFunc</link> func);
<link linkend="gint">gint</link>        <link linkend="g-list-position">g_list_position</link>                 (<link linkend="GList">GList</link> *list,
                                             <link linkend="GList">GList</link> *llink);
<link linkend="gint">gint</link>        <link linkend="g-list-index">g_list_index</link>                    (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data);

void        <link linkend="g-list-push-allocator">g_list_push_allocator</link>           (<link linkend="GAllocator">GAllocator</link> *allocator);
void        <link linkend="g-list-pop-allocator">g_list_pop_allocator</link>            (void);
</synopsis>
</refsynopsisdiv>





<refsect1>
<title>Description</title>
<para>
The <link linkend="GList">GList</link> structure and its associated functions provide a standard
doubly-linked list data structure.
</para>
<para>
Each element in the list contains a piece of data, together with pointers
which link to the previous and next elements in the list.
Using these pointers it is possible to move through the list in both
directions (unlike the
<link linkend="glib-Singly-Linked-lists">Singly-Linked Lists</link>
which only allows movement through the list in the forward direction).
</para>
<para>
The data contained in each element can be either integer values, by using one
of the
<link linkend="glib-Type-Conversion-Macros">Type Conversion Macros</link>,
or simply pointers to any type of data.
</para>
<para>
List elements are allocated in blocks using a <link linkend="GListAllocator">GListAllocator</link>, which is
more efficient than allocating elements individually.
</para>
<para>
Note that most of the <link linkend="GList">GList</link> functions expect to be passed a pointer to
the first element in the list. The functions which insert elements return
the new start of the list, which may have changed.
</para>
<para>
There is no function to create a <link linkend="GList">GList</link>. <literal>NULL</literal> is considered to be the empty
list so you simply set a <link linkend="GList">GList</link>* to <literal>NULL</literal>.
</para>
<para>
To add elements, use <link linkend="g-list-append">g_list_append</link>(), <link linkend="g-list-prepend">g_list_prepend</link>(), <link linkend="g-list-insert">g_list_insert</link>()
and <link linkend="g-list-insert-sorted">g_list_insert_sorted</link>().
</para>
<para>
To remove elements, use <link linkend="g-list-remove">g_list_remove</link>().
</para>
<para>
To find elements in the list use <link linkend="g-list-first">g_list_first</link>(), <link linkend="g-list-last">g_list_last</link>(), <link linkend="g-list-next">g_list_next</link>(),
<link linkend="g-list-previous">g_list_previous</link>(), <link linkend="g-list-nth">g_list_nth</link>(), <link linkend="g-list-nth-data">g_list_nth_data</link>(), <link linkend="g-list-find">g_list_find</link>() and
<link linkend="g-list-find-custom">g_list_find_custom</link>().
</para>
<para>
To find the index of an element use <link linkend="g-list-position">g_list_position</link>() and <link linkend="g-list-index">g_list_index</link>().
</para>
<para>
To call a function for each element in the list use <link linkend="g-list-foreach">g_list_foreach</link>().
</para>
<para>
To free the entire list, use <link linkend="g-list-free">g_list_free</link>().
</para>
</refsect1>

<refsect1>
<title>Details</title>
<refsect2>
<title><anchor id="GList">struct GList</title>
<programlisting>struct GList
{
  gpointer data;
  GList *next;
  GList *prev;
};
</programlisting>
<para>
The <link linkend="GList">GList</link> struct is used for each element in a doubly-linked list.
The <structfield>data</structfield> field holds the element's data, which can
be a pointer to any kind of data, or any integer value using the
<link linkend="glib-Type-Conversion-Macros">Type Conversion Macros</link>.
The <structfield>next</structfield> and <structfield>prev</structfield>
pointers are the links to the next and previous elements in the list.
</para></refsect2>
<refsect2>
<title><anchor id="g-list-append">g_list_append ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_append                   (<link linkend="GList">GList</link> *list,
                                             <link linkend="gpointer">gpointer</link> data);</programlisting>
<para>
Adds a new element on to the end of the list.
</para>
<note>
<para>
The return value is the new start of the list, which may have changed, so
make sure you store the new value.
</para>
</note>
<informalexample><programlisting>
  /* Notice that these are initialized to the empty list. */
  GList *list = NULL, *number_list = NULL;

  /* This is a list of strings. */
  list = g_list_append (list, "first");
  list = g_list_append (list, "second");

  /* This is a list of integers. */
  number_list = g_list_append (number_list, GINT_TO_POINTER (27));
  number_list = g_list_append (number_list, GINT_TO_POINTER (14));
</programlisting></informalexample><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a pointer to a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>the data for the new element.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new start of the <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-prepend">g_list_prepend ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_prepend                  (<link linkend="GList">GList</link> *list,
                                             <link linkend="gpointer">gpointer</link> data);</programlisting>
<para>
Adds a new element on to the start of the list.
</para>
<note>
<para>
The return value is the new start of the list, which may have changed, so
make sure you store the new value.
</para>
</note>
<informalexample><programlisting>
  /* Notice that it is initialized to the empty list. */
  GList *list = NULL;
  list = g_list_prepend (list, "last");
  list = g_list_prepend (list, "first");
</programlisting></informalexample><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a pointer to a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>the data for the new element.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new start of the <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-insert">g_list_insert ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_insert                   (<link linkend="GList">GList</link> *list,
                                             <link linkend="gpointer">gpointer</link> data,
                                             <link linkend="gint">gint</link> position);</programlisting>
<para>
Inserts a new element into the list at the given position.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a pointer to a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>the data for the new element.
</entry></row>
<row><entry align="right"><parameter>position</parameter>&nbsp;:</entry>
<entry>the position to insert the element. If this is negative, or is
larger than the number of elements in the list, the new element is added on
to the end of the list.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new start of the <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-insert-before">g_list_insert_before ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_insert_before            (<link linkend="GList">GList</link> *list,
                                             <link linkend="GList">GList</link> *sibling,
                                             <link linkend="gpointer">gpointer</link> data);</programlisting>
<para>
Inserts a new element into the list before the given position.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a pointer to a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>sibling</parameter>&nbsp;:</entry>
<entry>the list element before which the new element is inserted
  or <literal>NULL</literal> to insert at the end of the list.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>the data for the new element.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new start of the <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-insert-sorted">g_list_insert_sorted ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_insert_sorted            (<link linkend="GList">GList</link> *list,
                                             <link linkend="gpointer">gpointer</link> data,
                                             <link linkend="GCompareFunc">GCompareFunc</link> func);</programlisting>
<para>
Inserts a new element into the list, using the given comparison function
to determine its position.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a pointer to a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>the data for the new element.
</entry></row>
<row><entry align="right"><parameter>func</parameter>&nbsp;:</entry>
<entry>the function to compare elements in the list. It should return a
number > 0 if the first parameter comes after the second parameter in
the sort order.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new start of the <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-remove">g_list_remove ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_remove                   (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data);</programlisting>
<para>
Removes an element from a <link linkend="GList">GList</link>.
If two elements contain the same data, only the first is removed.
If none of the elements contain the data, the <link linkend="GList">GList</link> is unchanged.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>the data of the element to remove.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new start of the <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-remove-link">g_list_remove_link ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_remove_link              (<link linkend="GList">GList</link> *list,
                                             <link linkend="GList">GList</link> *llink);</programlisting>
<para>
Removes an element from a <link linkend="GList">GList</link>, without freeing the element.
The removed element's prev and next links are set to <literal>NULL</literal>, so that it becomes a
self-contained list with one element.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>llink</parameter>&nbsp;:</entry>
<entry>an element in the <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new start of the <link linkend="GList">GList</link>, without the element.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-delete-link">g_list_delete_link ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_delete_link              (<link linkend="GList">GList</link> *list,
                                             <link linkend="GList">GList</link> *link);</programlisting>
<para>
Deletes the node <parameter>link</parameter> from <parameter>list</parameter>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>link</parameter>&nbsp;:</entry>
<entry>node to delete from <parameter>list</parameter>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new head of <parameter>list</parameter>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-remove-all">g_list_remove_all ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_remove_all               (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data);</programlisting>
<para>
Removes all list nodes with data equal to <parameter>data</parameter>. Returns the new
head of the list. Contrast with <link linkend="g-list-remove">g_list_remove</link>() which removes only 
the first node matching the given data.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>data to remove.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>new head of <parameter>list</parameter>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-free">g_list_free ()</title>
<programlisting>void        g_list_free                     (<link linkend="GList">GList</link> *list);</programlisting>
<para>
Frees all of the memory used by a <link linkend="GList">GList</link>.
The freed elements are added to the <link linkend="GListAllocator">GListAllocator</link> free list.
</para>
<note>
<para>
If list elements contain dynamically-allocated memory, they should be freed
first.
</para>
</note><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-alloc">g_list_alloc ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_alloc                    (void);</programlisting>
<para>
Allocates space for one <link linkend="GList">GList</link> element.
It is called by <link linkend="g-list-append">g_list_append</link>(), <link linkend="g-list-prepend">g_list_prepend</link>(), <link linkend="g-list-insert">g_list_insert</link>() and
<link linkend="g-list-insert-sorted">g_list_insert_sorted</link>() and so is rarely used on its own.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>a pointer to the newly-allocated <link linkend="GList">GList</link> element.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-free-1">g_list_free_1 ()</title>
<programlisting>void        g_list_free_1                   (<link linkend="GList">GList</link> *list);</programlisting>
<para>
Frees one <link linkend="GList">GList</link> element.
It is usually used after <link linkend="g-list-remove-link">g_list_remove_link</link>().
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link> element.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-length">g_list_length ()</title>
<programlisting><link linkend="guint">guint</link>       g_list_length                   (<link linkend="GList">GList</link> *list);</programlisting>
<para>
Gets the number of elements in a <link linkend="GList">GList</link>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the number of elements in the <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-copy">g_list_copy ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_copy                     (<link linkend="GList">GList</link> *list);</programlisting>
<para>
Copies a <link linkend="GList">GList</link>.
</para>
<para>
Note that this is a "shallow" copy. If the list elements consist of pointers
to data, the pointers are copied but the actual data isn't.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>a copy of <parameter>list</parameter>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-reverse">g_list_reverse ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_reverse                  (<link linkend="GList">GList</link> *list);</programlisting>
<para>
Reverses a <link linkend="GList">GList</link>.
It simply switches the next and prev pointers of each element.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the start of the reversed <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-sort">g_list_sort ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_sort                     (<link linkend="GList">GList</link> *list,
                                             <link linkend="GCompareFunc">GCompareFunc</link> compare_func);</programlisting>
<para>
Sorts a <link linkend="GList">GList</link> using the given comparison function.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>compare_func</parameter>&nbsp;:</entry>
<entry>the comparison function used to sort the <link linkend="GList">GList</link>. This function
is passed 2 elements of the <link linkend="GList">GList</link> and should return 0 if they are equal,
a negative value if the first element comes before the second, or a positive
value if the first element comes after the second.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the start of the sorted <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="GCompareFunc">GCompareFunc ()</title>
<programlisting><link linkend="gint">gint</link>        (*GCompareFunc)                 (<link linkend="gconstpointer">gconstpointer</link> a,
                                             <link linkend="gconstpointer">gconstpointer</link> b);</programlisting>
<para>
Specifies the type of a comparison function used to compare two
values.  The function should return a negative integer if the first
value comes before the second, 0 if they are equal, or a positive
integer if the first value comes after the second.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>a</parameter>&nbsp;:</entry>
<entry>a value.
</entry></row>
<row><entry align="right"><parameter>b</parameter>&nbsp;:</entry>
<entry>a value to compare with.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>negative value if <parameter>a</parameter> < <parameter>b</parameter>; zero if <parameter>a</parameter> = <parameter>b</parameter>; positive value
if <parameter>a</parameter> > <parameter>b</parameter>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-sort-with-data">g_list_sort_with_data ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_sort_with_data           (<link linkend="GList">GList</link> *list,
                                             <link linkend="GCompareDataFunc">GCompareDataFunc</link> compare_func,
                                             <link linkend="gpointer">gpointer</link> user_data);</programlisting>
<para>
Like <link linkend="g-list-sort">g_list_sort</link>(), but the comparison function accepts a user data argument.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>compare_func</parameter>&nbsp;:</entry>
<entry>comparison function.
</entry></row>
<row><entry align="right"><parameter>user_data</parameter>&nbsp;:</entry>
<entry>user data to pass to comparison function.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new head of <parameter>list</parameter>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="GCompareDataFunc">GCompareDataFunc ()</title>
<programlisting><link linkend="gint">gint</link>        (*GCompareDataFunc)             (<link linkend="gconstpointer">gconstpointer</link> a,
                                             <link linkend="gconstpointer">gconstpointer</link> b,
                                             <link linkend="gpointer">gpointer</link> user_data);</programlisting>
<para>
Specifies the type of a comparison function used to compare two
values.  The function should return a negative integer if the first
value comes before the second, 0 if they are equal, or a positive
integer if the first value comes after the second.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>a</parameter>&nbsp;:</entry>
<entry>a value.
</entry></row>
<row><entry align="right"><parameter>b</parameter>&nbsp;:</entry>
<entry>a value to compare with.
</entry></row>
<row><entry align="right"><parameter>user_data</parameter>&nbsp;:</entry>
<entry>user data to pass to comparison function.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>negative value if <parameter>a</parameter> < <parameter>b</parameter>; zero if <parameter>a</parameter> = <parameter>b</parameter>; positive value
if <parameter>a</parameter> > <parameter>b</parameter>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-concat">g_list_concat ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_concat                   (<link linkend="GList">GList</link> *list1,
                                             <link linkend="GList">GList</link> *list2);</programlisting>
<para>
Adds the second <link linkend="GList">GList</link> onto the end of the first <link linkend="GList">GList</link>.
Note that the elements of the second <link linkend="GList">GList</link> are not copied.
They are used directly.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list1</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>list2</parameter>&nbsp;:</entry>
<entry>the <link linkend="GList">GList</link> to add to the end of the first <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the start of the new <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-foreach">g_list_foreach ()</title>
<programlisting>void        g_list_foreach                  (<link linkend="GList">GList</link> *list,
                                             <link linkend="GFunc">GFunc</link> func,
                                             <link linkend="gpointer">gpointer</link> user_data);</programlisting>
<para>
Calls a function for each element of a <link linkend="GList">GList</link>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>func</parameter>&nbsp;:</entry>
<entry>the function to call with each element's data.
</entry></row>
<row><entry align="right"><parameter>user_data</parameter>&nbsp;:</entry>
<entry>user data to pass to the function.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="GFunc">GFunc ()</title>
<programlisting>void        (*GFunc)                        (<link linkend="gpointer">gpointer</link> data,
                                             <link linkend="gpointer">gpointer</link> user_data);</programlisting>
<para>
Specifies the type of functions passed to <link linkend="g-list-foreach">g_list_foreach</link>() and
<link linkend="g-slist-foreach">g_slist_foreach</link>().
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>the element's data.
</entry></row>
<row><entry align="right"><parameter>user_data</parameter>&nbsp;:</entry>
<entry>user data passed to <link linkend="g-list-foreach">g_list_foreach</link>() or <link linkend="g-slist-foreach">g_slist_foreach</link>().


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-first">g_list_first ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_first                    (<link linkend="GList">GList</link> *list);</programlisting>
<para>
Gets the first element in a <link linkend="GList">GList</link>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the first element in a <link linkend="GList">GList</link>, or <literal>NULL</literal> if the <link linkend="GList">GList</link> has no elements.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-last">g_list_last ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_last                     (<link linkend="GList">GList</link> *list);</programlisting>
<para>
Gets the last element in a <link linkend="GList">GList</link>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the last element in the <link linkend="GList">GList</link>, or <literal>NULL</literal> if the <link linkend="GList">GList</link> has no
elements.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-previous">g_list_previous()</title>
<programlisting>#define     g_list_previous(list)</programlisting>
<para>
A convenience macro to gets the previous element in a <link linkend="GList">GList</link>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>an element in a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the previous element, or <literal>NULL</literal> if there are no previous elements.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-next">g_list_next()</title>
<programlisting>#define     g_list_next(list)</programlisting>
<para>
A convenience macro to gets the next element in a <link linkend="GList">GList</link>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>an element in a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the next element, or <literal>NULL</literal> if there are no more elements.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-nth">g_list_nth ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_nth                      (<link linkend="GList">GList</link> *list,
                                             <link linkend="guint">guint</link> n);</programlisting>
<para>
Gets the element at the given position in a <link linkend="GList">GList</link>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>n</parameter>&nbsp;:</entry>
<entry>the position of the element, counting from 0.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the element, or <literal>NULL</literal> if the position is off the end of the <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-nth-data">g_list_nth_data ()</title>
<programlisting><link linkend="gpointer">gpointer</link>    g_list_nth_data                 (<link linkend="GList">GList</link> *list,
                                             <link linkend="guint">guint</link> n);</programlisting>
<para>
Gets the data of the element at the given position.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>n</parameter>&nbsp;:</entry>
<entry>the position of the element.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the element's data, or <literal>NULL</literal> if the position is off the end of the
<link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-nth-prev">g_list_nth_prev ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_nth_prev                 (<link linkend="GList">GList</link> *list,
                                             <link linkend="guint">guint</link> n);</programlisting>
<para>
Gets the element <parameter>n</parameter> places before <parameter>list</parameter>.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>n</parameter>&nbsp;:</entry>
<entry>the position of the element, counting from 0.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the element, or <literal>NULL</literal> if the position is off the end of the <link linkend="GList">GList</link>.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-find">g_list_find ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_find                     (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data);</programlisting>
<para>
Finds the element in a <link linkend="GList">GList</link> which contains the given data.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>the element data to find.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the found <link linkend="GList">GList</link> element, or <literal>NULL</literal> if it is not found.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-find-custom">g_list_find_custom ()</title>
<programlisting><link linkend="GList">GList</link>*      g_list_find_custom              (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data,
                                             <link linkend="GCompareFunc">GCompareFunc</link> func);</programlisting>
<para>
Finds an element in a <link linkend="GList">GList</link>, using a supplied function to find the desired
element.
It iterates over the list, calling the given function which should return 0
when the desired element is found.
The function takes two <link linkend="gconstpointer">gconstpointer</link> arguments, the <link linkend="GList">GList</link> element's data
and the given user data.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>user data passed to the function.
</entry></row>
<row><entry align="right"><parameter>func</parameter>&nbsp;:</entry>
<entry>the function to call for each element. It should return 0 when the
desired element is found.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the found <link linkend="GList">GList</link> element, or <literal>NULL</literal> if it is not found.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-position">g_list_position ()</title>
<programlisting><link linkend="gint">gint</link>        g_list_position                 (<link linkend="GList">GList</link> *list,
                                             <link linkend="GList">GList</link> *llink);</programlisting>
<para>
Gets the position of the given element in the <link linkend="GList">GList</link> (starting from 0).
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>llink</parameter>&nbsp;:</entry>
<entry>an element in the <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the position of the element in the <link linkend="GList">GList</link>, or -1 if the element is
not found.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-index">g_list_index ()</title>
<programlisting><link linkend="gint">gint</link>        g_list_index                    (<link linkend="GList">GList</link> *list,
                                             <link linkend="gconstpointer">gconstpointer</link> data);</programlisting>
<para>
Gets the position of the element containing the given data (starting from 0).
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>list</parameter>&nbsp;:</entry>
<entry>a <link linkend="GList">GList</link>.
</entry></row>
<row><entry align="right"><parameter>data</parameter>&nbsp;:</entry>
<entry>the data to find.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the index of the element containing the data, or -1 if the data
is not found.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-push-allocator">g_list_push_allocator ()</title>
<programlisting>void        g_list_push_allocator           (<link linkend="GAllocator">GAllocator</link> *allocator);</programlisting>
<para>
Sets the allocator to use to allocate <link linkend="GList">GList</link> elements.
Use <link linkend="g-list-pop-allocator">g_list_pop_allocator</link>() to restore the previous allocator.
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>allocator</parameter>&nbsp;:</entry>
<entry>the <link linkend="GAllocator">GAllocator</link> to use when allocating <link linkend="GList">GList</link> elements.


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="g-list-pop-allocator">g_list_pop_allocator ()</title>
<programlisting>void        g_list_pop_allocator            (void);</programlisting>
<para>
Restores the previous <link linkend="GAllocator">GAllocator</link>, used when allocating <link linkend="GList">GList</link> elements.
</para></refsect2>

</refsect1>




</refentry>
