<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN'
                      'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [
<!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="glib-Singly-Linked-Lists">
<refmeta>
<refentrytitle role="top_of_page" id="glib-Singly-Linked-Lists.top_of_page">Singly-Linked Lists</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GLIB Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>Singly-Linked Lists</refname>
<refpurpose>linked lists that can be iterated in one direction</refpurpose>
</refnamediv>

<refsect1 id="glib-Singly-Linked-Lists.functions" role="functions_proto">
<title role="functions_proto.title">Functions</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="functions_return" colwidth="150px"/>
<colspec colname="functions_name"/>
<tbody>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-alloc">g_slist_alloc</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-append">g_slist_append</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-prepend">g_slist_prepend</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-insert">g_slist_insert</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-insert-before">g_slist_insert_before</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-insert-sorted">g_slist_insert_sorted</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-remove">g_slist_remove</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-remove-link">g_slist_remove_link</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-delete-link">g_slist_delete_link</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-remove-all">g_slist_remove_all</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-slist-free">g_slist_free</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-slist-free-full">g_slist_free_full</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-slist-free-1">g_slist_free_1</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

<row><entry role="function_type"><link linkend="guint"><returnvalue>guint</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-slist-length">g_slist_length</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-copy">g_slist_copy</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-copy-deep">g_slist_copy_deep</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-reverse">g_slist_reverse</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-insert-sorted-with-data">g_slist_insert_sorted_with_data</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-sort">g_slist_sort</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-sort-with-data">g_slist_sort_with_data</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-concat">g_slist_concat</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-slist-foreach">g_slist_foreach</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-last">g_slist_last</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-slist-next">g_slist_next</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-nth">g_slist_nth</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gpointer"><returnvalue>gpointer</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-slist-nth-data">g_slist_nth_data</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-find">g_slist_find</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="g-slist-find-custom">g_slist_find_custom</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gint"><returnvalue>gint</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-slist-position">g_slist_position</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gint"><returnvalue>gint</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-slist-index">g_slist_index</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="glib-Singly-Linked-Lists.other" role="other_proto">
<title role="other_proto.title">Types and Values</title>
<informaltable role="enum_members_table" pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="name" colwidth="150px"/>
<colspec colname="description"/>
<tbody>
<row><entry role="datatype_keyword">struct</entry><entry role="function_name"><link linkend="GSList">GSList</link></entry></row>

<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-slist-free1">g_slist_free1</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 id="glib-Singly-Linked-Lists.includes"><title>Includes</title><synopsis>#include &lt;gmodule.h&gt;
</synopsis></refsect1>

<refsect1 id="glib-Singly-Linked-Lists.description" role="desc">
<title role="desc.title">Description</title>
<para>The <link linkend="GSList"><type>GSList</type></link> structure and its associated functions provide a
standard singly-linked list data structure.</para>
<para>Each element in the list contains a piece of data, together with a
pointer which links to the next element in the list. Using this
pointer it is possible to move through the list in one direction
only (unlike the <link linkend="glib-Doubly-Linked-Lists">double-linked lists</link>,
which allow movement in both directions).</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 from the <link linkend="glib-Memory-Slices">slice allocator</link>,
which is more efficient than allocating elements individually.</para>
<para>Note that most of the <link linkend="GSList"><type>GSList</type></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="GSList"><type>GSList</type></link>. <link linkend="NULL:CAPS"><literal>NULL</literal></link> is considered to be
the empty list so you simply set a <link linkend="GSList"><type>GSList</type></link>* to <link linkend="NULL:CAPS"><literal>NULL</literal></link>.</para>
<para>To add elements, use <link linkend="g-slist-append"><function>g_slist_append()</function></link>, <link linkend="g-slist-prepend"><function>g_slist_prepend()</function></link>,
<link linkend="g-slist-insert"><function>g_slist_insert()</function></link> and <link linkend="g-slist-insert-sorted"><function>g_slist_insert_sorted()</function></link>.</para>
<para>To remove elements, use <link linkend="g-slist-remove"><function>g_slist_remove()</function></link>.</para>
<para>To find elements in the list use <link linkend="g-slist-last"><function>g_slist_last()</function></link>, <link linkend="g-slist-next"><function>g_slist_next()</function></link>,
<link linkend="g-slist-nth"><function>g_slist_nth()</function></link>, <link linkend="g-slist-nth-data"><function>g_slist_nth_data()</function></link>, <link linkend="g-slist-find"><function>g_slist_find()</function></link> and
<link linkend="g-slist-find-custom"><function>g_slist_find_custom()</function></link>.</para>
<para>To find the index of an element use <link linkend="g-slist-position"><function>g_slist_position()</function></link> and
<link linkend="g-slist-index"><function>g_slist_index()</function></link>.</para>
<para>To call a function for each element in the list use
<link linkend="g-slist-foreach"><function>g_slist_foreach()</function></link>.</para>
<para>To free the entire list, use <link linkend="g-slist-free"><function>g_slist_free()</function></link>.</para>

</refsect1>
<refsect1 id="glib-Singly-Linked-Lists.functions_details" role="details">
<title role="details.title">Functions</title>
<refsect2 id="g-slist-alloc" role="function">
<title>g_slist_alloc&#160;()</title>
<indexterm zone="g-slist-alloc"><primary sortas="slist_alloc">g_slist_alloc</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_alloc (<parameter><type>void</type></parameter>);</programlisting>
<para>Allocates space for one <link linkend="GSList"><type>GSList</type></link> element. It is called by the
<link linkend="g-slist-append"><function>g_slist_append()</function></link>, <link linkend="g-slist-prepend"><function>g_slist_prepend()</function></link>, <link linkend="g-slist-insert"><function>g_slist_insert()</function></link> and
<link linkend="g-slist-insert-sorted"><function>g_slist_insert_sorted()</function></link> functions and so is rarely used on its own.</para>
<refsect3 id="g-slist-alloc.returns" role="returns">
<title>Returns</title>
<para> a pointer to the newly-allocated <link linkend="GSList"><type>GSList</type></link> element.</para>
</refsect3></refsect2>
<refsect2 id="g-slist-append" role="function">
<title>g_slist_append&#160;()</title>
<indexterm zone="g-slist-append"><primary sortas="slist_append">g_slist_append</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_append (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                <parameter><link linkend="gpointer"><type>gpointer</type></link> data</parameter>);</programlisting>
<para>Adds a new element on to the end of the list.</para>
<para>The return value is the new start of the list, which may
have changed, so make sure you store the new value.</para>
<para>Note that <link linkend="g-slist-append"><function>g_slist_append()</function></link> has to traverse the entire list
to find the end, which is inefficient when adding multiple
elements. A common idiom to avoid the inefficiency is to prepend
the elements and reverse the list when all elements have been added.</para>
<informalexample><programlisting role="example"><![CDATA[
// Notice that these are initialized to the empty list.
GSList *list = NULL, *number_list = NULL;

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

// This is a list of integers.
number_list = g_slist_append (number_list, GINT_TO_POINTER (27));
number_list = g_slist_append (number_list, GINT_TO_POINTER (14));
]]></programlisting></informalexample>
<para></para>
<refsect3 id="g-slist-append.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>the data for the new element</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-append.returns" role="returns">
<title>Returns</title>
<para> the new start of the <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-prepend" role="function">
<title>g_slist_prepend&#160;()</title>
<indexterm zone="g-slist-prepend"><primary sortas="slist_prepend">g_slist_prepend</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_prepend (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                 <parameter><link linkend="gpointer"><type>gpointer</type></link> data</parameter>);</programlisting>
<para>Adds a new element on to the start of the list.</para>
<para>The return value is the new start of the list, which
may have changed, so make sure you store the new value.</para>
<informalexample><programlisting role="example"><![CDATA[
// Notice that it is initialized to the empty list.
GSList *list = NULL;
list = g_slist_prepend (list, "last");
list = g_slist_prepend (list, "first");
]]></programlisting></informalexample>
<para></para>
<refsect3 id="g-slist-prepend.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>the data for the new element</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-prepend.returns" role="returns">
<title>Returns</title>
<para> the new start of the <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-insert" role="function">
<title>g_slist_insert&#160;()</title>
<indexterm zone="g-slist-insert"><primary sortas="slist_insert">g_slist_insert</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_insert (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                <parameter><link linkend="gpointer"><type>gpointer</type></link> data</parameter>,
                <parameter><link linkend="gint"><type>gint</type></link> position</parameter>);</programlisting>
<para>Inserts a new element into the list at the given position.</para>
<refsect3 id="g-slist-insert.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>the data for the new element</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>position</para></entry>
<entry role="parameter_description"><para>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.</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-insert.returns" role="returns">
<title>Returns</title>
<para> the new start of the <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-insert-before" role="function">
<title>g_slist_insert_before&#160;()</title>
<indexterm zone="g-slist-insert-before"><primary sortas="slist_insert_before">g_slist_insert_before</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_insert_before (<parameter><link linkend="GSList"><type>GSList</type></link> *slist</parameter>,
                       <parameter><link linkend="GSList"><type>GSList</type></link> *sibling</parameter>,
                       <parameter><link linkend="gpointer"><type>gpointer</type></link> data</parameter>);</programlisting>
<para>Inserts a node before <parameter>sibling</parameter>
 containing <parameter>data</parameter>
.</para>
<refsect3 id="g-slist-insert-before.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>slist</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>sibling</para></entry>
<entry role="parameter_description"><para>node to insert <parameter>data</parameter>
before</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>data to put in the newly-inserted node</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-insert-before.returns" role="returns">
<title>Returns</title>
<para> the new head of the list.</para>
</refsect3></refsect2>
<refsect2 id="g-slist-insert-sorted" role="function">
<title>g_slist_insert_sorted&#160;()</title>
<indexterm zone="g-slist-insert-sorted"><primary sortas="slist_insert_sorted">g_slist_insert_sorted</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_insert_sorted (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                       <parameter><link linkend="gpointer"><type>gpointer</type></link> data</parameter>,
                       <parameter><link linkend="GCompareFunc"><type>GCompareFunc</type></link> func</parameter>);</programlisting>
<para>Inserts a new element into the list, using the given
comparison function to determine its position.</para>
<refsect3 id="g-slist-insert-sorted.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>the data for the new element</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>func</para></entry>
<entry role="parameter_description"><para>the function to compare elements in the list.
It should return a number &gt; 0 if the first parameter
comes after the second parameter in the sort order.</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-insert-sorted.returns" role="returns">
<title>Returns</title>
<para> the new start of the <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-remove" role="function">
<title>g_slist_remove&#160;()</title>
<indexterm zone="g-slist-remove"><primary sortas="slist_remove">g_slist_remove</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_remove (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                <parameter><link linkend="gconstpointer"><type>gconstpointer</type></link> data</parameter>);</programlisting>
<para>Removes an element from a <link linkend="GSList"><type>GSList</type></link>.
If two elements contain the same data, only the first is removed.
If none of the elements contain the data, the <link linkend="GSList"><type>GSList</type></link> is unchanged.</para>
<refsect3 id="g-slist-remove.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>the data of the element to remove</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-remove.returns" role="returns">
<title>Returns</title>
<para> the new start of the <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-remove-link" role="function">
<title>g_slist_remove_link&#160;()</title>
<indexterm zone="g-slist-remove-link"><primary sortas="slist_remove_link">g_slist_remove_link</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_remove_link (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                     <parameter><link linkend="GSList"><type>GSList</type></link> *link_</parameter>);</programlisting>
<para>Removes an element from a <link linkend="GSList"><type>GSList</type></link>, without
freeing the element. The removed element's next
link is set to <link linkend="NULL:CAPS"><literal>NULL</literal></link>, so that it becomes a
self-contained list with one element.</para>
<para>Removing arbitrary nodes from a singly-linked list
requires time that is proportional to the length of the list
(ie. O(n)). If you find yourself using <link linkend="g-slist-remove-link"><function>g_slist_remove_link()</function></link>
frequently, you should consider a different data structure,
such as the doubly-linked <link linkend="GList"><type>GList</type></link>.</para>
<refsect3 id="g-slist-remove-link.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>link_</para></entry>
<entry role="parameter_description"><para>an element in the <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-remove-link.returns" role="returns">
<title>Returns</title>
<para> the new start of the <link linkend="GSList"><type>GSList</type></link>, without the element</para>
</refsect3></refsect2>
<refsect2 id="g-slist-delete-link" role="function">
<title>g_slist_delete_link&#160;()</title>
<indexterm zone="g-slist-delete-link"><primary sortas="slist_delete_link">g_slist_delete_link</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_delete_link (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                     <parameter><link linkend="GSList"><type>GSList</type></link> *link_</parameter>);</programlisting>
<para>Removes the node link_ from the list and frees it.
Compare this to <link linkend="g-slist-remove-link"><function>g_slist_remove_link()</function></link> which removes the node
without freeing it.</para>
<para>Removing arbitrary nodes from a singly-linked list requires time
that is proportional to the length of the list (ie. O(n)). If you
find yourself using <link linkend="g-slist-delete-link"><function>g_slist_delete_link()</function></link> frequently, you should
consider a different data structure, such as the doubly-linked
<link linkend="GList"><type>GList</type></link>.</para>
<refsect3 id="g-slist-delete-link.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>link_</para></entry>
<entry role="parameter_description"><para>node to delete</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-delete-link.returns" role="returns">
<title>Returns</title>
<para> the new head of <parameter>list</parameter>
</para>
</refsect3></refsect2>
<refsect2 id="g-slist-remove-all" role="function">
<title>g_slist_remove_all&#160;()</title>
<indexterm zone="g-slist-remove-all"><primary sortas="slist_remove_all">g_slist_remove_all</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_remove_all (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                    <parameter><link linkend="gconstpointer"><type>gconstpointer</type></link> data</parameter>);</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-slist-remove"><function>g_slist_remove()</function></link> which removes only the first node
matching the given data.</para>
<refsect3 id="g-slist-remove-all.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>data to remove</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-remove-all.returns" role="returns">
<title>Returns</title>
<para> new head of <parameter>list</parameter>
</para>
</refsect3></refsect2>
<refsect2 id="g-slist-free" role="function">
<title>g_slist_free&#160;()</title>
<indexterm zone="g-slist-free"><primary sortas="slist_free">g_slist_free</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
g_slist_free (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>);</programlisting>
<para>Frees all of the memory used by a <link linkend="GSList"><type>GSList</type></link>.
The freed elements are returned to the slice allocator.</para>
<para>If list elements contain dynamically-allocated memory,
you should either use <link linkend="g-slist-free-full"><function>g_slist_free_full()</function></link> or free them manually
first.</para>
<refsect3 id="g-slist-free.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="g-slist-free-full" role="function" condition="since:2.28">
<title>g_slist_free_full&#160;()</title>
<indexterm zone="g-slist-free-full" role="2.28"><primary sortas="slist_free_full">g_slist_free_full</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
g_slist_free_full (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                   <parameter><link linkend="GDestroyNotify"><type>GDestroyNotify</type></link> free_func</parameter>);</programlisting>
<para>Convenience method, which frees all the memory used by a <link linkend="GSList"><type>GSList</type></link>, and
calls the specified destroy function on every element's data.</para>
<para><parameter>free_func</parameter>
 must not modify the list (eg, by removing the freed
element from it).</para>
<refsect3 id="g-slist-free-full.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a pointer to a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>free_func</para></entry>
<entry role="parameter_description"><para>the function to be called to free each element's data</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.28">2.28</link></para></refsect2>
<refsect2 id="g-slist-free-1" role="function">
<title>g_slist_free_1&#160;()</title>
<indexterm zone="g-slist-free-1"><primary sortas="slist_free_1">g_slist_free_1</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
g_slist_free_1 (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>);</programlisting>
<para>Frees one <link linkend="GSList"><type>GSList</type></link> element.
It is usually used after <link linkend="g-slist-remove-link"><function>g_slist_remove_link()</function></link>.</para>
<refsect3 id="g-slist-free-1.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link> element</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="g-slist-length" role="function">
<title>g_slist_length&#160;()</title>
<indexterm zone="g-slist-length"><primary sortas="slist_length">g_slist_length</primary></indexterm>
<programlisting language="C"><link linkend="guint"><returnvalue>guint</returnvalue></link>
g_slist_length (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>);</programlisting>
<para>Gets the number of elements in a <link linkend="GSList"><type>GSList</type></link>.</para>
<para>This function iterates over the whole list to
count its elements. To check whether the list is non-empty, it is faster to
check <parameter>list</parameter>
 against <link linkend="NULL:CAPS"><literal>NULL</literal></link>.</para>
<refsect3 id="g-slist-length.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-length.returns" role="returns">
<title>Returns</title>
<para> the number of elements in the <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-copy" role="function">
<title>g_slist_copy&#160;()</title>
<indexterm zone="g-slist-copy"><primary sortas="slist_copy">g_slist_copy</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_copy (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>);</programlisting>
<para>Copies a <link linkend="GSList"><type>GSList</type></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. See <link linkend="g-slist-copy-deep"><function>g_slist_copy_deep()</function></link> if you need
to copy the data as well.</para>
<refsect3 id="g-slist-copy.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-copy.returns" role="returns">
<title>Returns</title>
<para> a copy of <parameter>list</parameter>
</para>
</refsect3></refsect2>
<refsect2 id="g-slist-copy-deep" role="function" condition="since:2.34">
<title>g_slist_copy_deep&#160;()</title>
<indexterm zone="g-slist-copy-deep" role="2.34"><primary sortas="slist_copy_deep">g_slist_copy_deep</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_copy_deep (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                   <parameter><link linkend="GCopyFunc"><type>GCopyFunc</type></link> func</parameter>,
                   <parameter><link linkend="gpointer"><type>gpointer</type></link> user_data</parameter>);</programlisting>
<para>Makes a full (deep) copy of a <link linkend="GSList"><type>GSList</type></link>.</para>
<para>In contrast with <link linkend="g-slist-copy"><function>g_slist_copy()</function></link>, this function uses <parameter>func</parameter>
 to make a copy of
each list element, in addition to copying the list container itself.</para>
<para><parameter>func</parameter>
, as a <link linkend="GCopyFunc"><type>GCopyFunc</type></link>, takes two arguments, the data to be copied
and a <parameter>user_data</parameter>
 pointer. On common processor architectures, it's safe to
pass <link linkend="NULL:CAPS"><literal>NULL</literal></link> as <parameter>user_data</parameter>
 if the copy function takes only one argument. You
may get compiler warnings from this though if compiling with GCC’s
<literal>-Wcast-function-type</literal> warning.</para>
<para>For instance, if <parameter>list</parameter>
 holds a list of GObjects, you can do:</para>
<informalexample><programlisting role="example"><![CDATA[
another_list = g_slist_copy_deep (list, (GCopyFunc) g_object_ref, NULL);
]]></programlisting></informalexample>
<para></para>
<para>And, to entirely free the new list, you could do:</para>
<informalexample><programlisting role="example"><![CDATA[
g_slist_free_full (another_list, g_object_unref);
]]></programlisting></informalexample>
<para></para>
<refsect3 id="g-slist-copy-deep.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>func</para></entry>
<entry role="parameter_description"><para>a copy function used to copy every element in the list</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>user_data</para></entry>
<entry role="parameter_description"><para>user data passed to the copy function <parameter>func</parameter>
, or <link linkend="NULL:CAPS"><type>NULL</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-copy-deep.returns" role="returns">
<title>Returns</title>
<para> a full copy of <parameter>list</parameter>
, use <link linkend="g-slist-free-full"><function>g_slist_free_full()</function></link> to free it</para>
</refsect3><para role="since">Since: <link linkend="api-index-2.34">2.34</link></para></refsect2>
<refsect2 id="g-slist-reverse" role="function">
<title>g_slist_reverse&#160;()</title>
<indexterm zone="g-slist-reverse"><primary sortas="slist_reverse">g_slist_reverse</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_reverse (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>);</programlisting>
<para>Reverses a <link linkend="GSList"><type>GSList</type></link>.</para>
<refsect3 id="g-slist-reverse.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-reverse.returns" role="returns">
<title>Returns</title>
<para> the start of the reversed <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-insert-sorted-with-data" role="function" condition="since:2.10">
<title>g_slist_insert_sorted_with_data&#160;()</title>
<indexterm zone="g-slist-insert-sorted-with-data" role="2.10"><primary sortas="slist_insert_sorted_with_data">g_slist_insert_sorted_with_data</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_insert_sorted_with_data (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                                 <parameter><link linkend="gpointer"><type>gpointer</type></link> data</parameter>,
                                 <parameter><link linkend="GCompareDataFunc"><type>GCompareDataFunc</type></link> func</parameter>,
                                 <parameter><link linkend="gpointer"><type>gpointer</type></link> user_data</parameter>);</programlisting>
<para>Inserts a new element into the list, using the given
comparison function to determine its position.</para>
<refsect3 id="g-slist-insert-sorted-with-data.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>the data for the new element</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>func</para></entry>
<entry role="parameter_description"><para>the function to compare elements in the list.
It should return a number &gt; 0 if the first parameter
comes after the second parameter in the sort order.</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>user_data</para></entry>
<entry role="parameter_description"><para>data to pass to comparison function</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-insert-sorted-with-data.returns" role="returns">
<title>Returns</title>
<para> the new start of the <link linkend="GSList"><type>GSList</type></link></para>
</refsect3><para role="since">Since: <link linkend="api-index-2.10">2.10</link></para></refsect2>
<refsect2 id="g-slist-sort" role="function">
<title>g_slist_sort&#160;()</title>
<indexterm zone="g-slist-sort"><primary sortas="slist_sort">g_slist_sort</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_sort (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
              <parameter><link linkend="GCompareFunc"><type>GCompareFunc</type></link> compare_func</parameter>);</programlisting>
<para>Sorts a <link linkend="GSList"><type>GSList</type></link> using the given comparison function. The algorithm
used is a stable sort.</para>
<refsect3 id="g-slist-sort.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>compare_func</para></entry>
<entry role="parameter_description"><para>the comparison function used to sort the <link linkend="GSList"><type>GSList</type></link>.
This function is passed the data from 2 elements of the <link linkend="GSList"><type>GSList</type></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.</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-sort.returns" role="returns">
<title>Returns</title>
<para> the start of the sorted <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-sort-with-data" role="function">
<title>g_slist_sort_with_data&#160;()</title>
<indexterm zone="g-slist-sort-with-data"><primary sortas="slist_sort_with_data">g_slist_sort_with_data</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_sort_with_data (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                        <parameter><link linkend="GCompareDataFunc"><type>GCompareDataFunc</type></link> compare_func</parameter>,
                        <parameter><link linkend="gpointer"><type>gpointer</type></link> user_data</parameter>);</programlisting>
<para>Like <link linkend="g-slist-sort"><function>g_slist_sort()</function></link>, but the sort function accepts a user data argument.</para>
<refsect3 id="g-slist-sort-with-data.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>compare_func</para></entry>
<entry role="parameter_description"><para>comparison function</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>user_data</para></entry>
<entry role="parameter_description"><para>data to pass to comparison function</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-sort-with-data.returns" role="returns">
<title>Returns</title>
<para> new head of the list</para>
</refsect3></refsect2>
<refsect2 id="g-slist-concat" role="function">
<title>g_slist_concat&#160;()</title>
<indexterm zone="g-slist-concat"><primary sortas="slist_concat">g_slist_concat</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_concat (<parameter><link linkend="GSList"><type>GSList</type></link> *list1</parameter>,
                <parameter><link linkend="GSList"><type>GSList</type></link> *list2</parameter>);</programlisting>
<para>Adds the second <link linkend="GSList"><type>GSList</type></link> onto the end of the first <link linkend="GSList"><type>GSList</type></link>.
Note that the elements of the second <link linkend="GSList"><type>GSList</type></link> are not copied.
They are used directly.</para>
<refsect3 id="g-slist-concat.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list1</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>list2</para></entry>
<entry role="parameter_description"><para>the <link linkend="GSList"><type>GSList</type></link> to add to the end of the first <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-concat.returns" role="returns">
<title>Returns</title>
<para> the start of the new <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-foreach" role="function">
<title>g_slist_foreach&#160;()</title>
<indexterm zone="g-slist-foreach"><primary sortas="slist_foreach">g_slist_foreach</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
g_slist_foreach (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                 <parameter><link linkend="GFunc"><type>GFunc</type></link> func</parameter>,
                 <parameter><link linkend="gpointer"><type>gpointer</type></link> user_data</parameter>);</programlisting>
<para>Calls a function for each element of a <link linkend="GSList"><type>GSList</type></link>.</para>
<para>It is safe for <parameter>func</parameter>
 to remove the element from <parameter>list</parameter>
, but it must
not modify any part of the list after that element.</para>
<refsect3 id="g-slist-foreach.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>func</para></entry>
<entry role="parameter_description"><para>the function to call with each element's data</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>user_data</para></entry>
<entry role="parameter_description"><para>user data to pass to the function</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="g-slist-last" role="function">
<title>g_slist_last&#160;()</title>
<indexterm zone="g-slist-last"><primary sortas="slist_last">g_slist_last</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_last (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>);</programlisting>
<para>Gets the last element in a <link linkend="GSList"><type>GSList</type></link>.</para>
<para>This function iterates over the whole list.</para>
<refsect3 id="g-slist-last.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-last.returns" role="returns">
<title>Returns</title>
<para> the last element in the <link linkend="GSList"><type>GSList</type></link>,
or <link linkend="NULL:CAPS"><literal>NULL</literal></link> if the <link linkend="GSList"><type>GSList</type></link> has no elements</para>
</refsect3></refsect2>
<refsect2 id="g-slist-next" role="macro">
<title>g_slist_next()</title>
<indexterm zone="g-slist-next"><primary sortas="slist_next">g_slist_next</primary></indexterm>
<programlisting language="C">#define             g_slist_next(slist)</programlisting>
<para>A convenience macro to get the next element in a <link linkend="GSList"><type>GSList</type></link>.
Note that it is considered perfectly acceptable to access
<parameter>slist->next</parameter>
 directly.</para>
<refsect3 id="g-slist-next.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>slist</para></entry>
<entry role="parameter_description"><para>an element in a <link linkend="GSList"><type>GSList</type></link>.</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-next.returns" role="returns">
<title>Returns</title>
<para> the next element, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> if there are no more elements.</para>
</refsect3></refsect2>
<refsect2 id="g-slist-nth" role="function">
<title>g_slist_nth&#160;()</title>
<indexterm zone="g-slist-nth"><primary sortas="slist_nth">g_slist_nth</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_nth (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
             <parameter><link linkend="guint"><type>guint</type></link> n</parameter>);</programlisting>
<para>Gets the element at the given position in a <link linkend="GSList"><type>GSList</type></link>.</para>
<refsect3 id="g-slist-nth.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>n</para></entry>
<entry role="parameter_description"><para>the position of the element, counting from 0</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-nth.returns" role="returns">
<title>Returns</title>
<para> the element, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> if the position is off
the end of the <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-nth-data" role="function">
<title>g_slist_nth_data&#160;()</title>
<indexterm zone="g-slist-nth-data"><primary sortas="slist_nth_data">g_slist_nth_data</primary></indexterm>
<programlisting language="C"><link linkend="gpointer"><returnvalue>gpointer</returnvalue></link>
g_slist_nth_data (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                  <parameter><link linkend="guint"><type>guint</type></link> n</parameter>);</programlisting>
<para>Gets the data of the element at the given position.</para>
<refsect3 id="g-slist-nth-data.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>n</para></entry>
<entry role="parameter_description"><para>the position of the element</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-nth-data.returns" role="returns">
<title>Returns</title>
<para> the element's data, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> if the position
is off the end of the <link linkend="GSList"><type>GSList</type></link></para>
</refsect3></refsect2>
<refsect2 id="g-slist-find" role="function">
<title>g_slist_find&#160;()</title>
<indexterm zone="g-slist-find"><primary sortas="slist_find">g_slist_find</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_find (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
              <parameter><link linkend="gconstpointer"><type>gconstpointer</type></link> data</parameter>);</programlisting>
<para>Finds the element in a <link linkend="GSList"><type>GSList</type></link> which
contains the given data.</para>
<refsect3 id="g-slist-find.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>the element data to find</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-find.returns" role="returns">
<title>Returns</title>
<para> the found <link linkend="GSList"><type>GSList</type></link> element,
or <link linkend="NULL:CAPS"><literal>NULL</literal></link> if it is not found</para>
</refsect3></refsect2>
<refsect2 id="g-slist-find-custom" role="function">
<title>g_slist_find_custom&#160;()</title>
<indexterm zone="g-slist-find-custom"><primary sortas="slist_find_custom">g_slist_find_custom</primary></indexterm>
<programlisting language="C"><link linkend="GSList"><returnvalue>GSList</returnvalue></link>&#160;*
g_slist_find_custom (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                     <parameter><link linkend="gconstpointer"><type>gconstpointer</type></link> data</parameter>,
                     <parameter><link linkend="GCompareFunc"><type>GCompareFunc</type></link> func</parameter>);</programlisting>
<para>Finds an element in a <link linkend="GSList"><type>GSList</type></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"><type>gconstpointer</type></link> arguments,
the <link linkend="GSList"><type>GSList</type></link> element's data as the first argument and the
given user data.</para>
<refsect3 id="g-slist-find-custom.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>user data passed to the function</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>func</para></entry>
<entry role="parameter_description"><para>the function to call for each element.
It should return 0 when the desired element is found</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-find-custom.returns" role="returns">
<title>Returns</title>
<para> the found <link linkend="GSList"><type>GSList</type></link> element, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> if it is not found</para>
</refsect3></refsect2>
<refsect2 id="g-slist-position" role="function">
<title>g_slist_position&#160;()</title>
<indexterm zone="g-slist-position"><primary sortas="slist_position">g_slist_position</primary></indexterm>
<programlisting language="C"><link linkend="gint"><returnvalue>gint</returnvalue></link>
g_slist_position (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
                  <parameter><link linkend="GSList"><type>GSList</type></link> *llink</parameter>);</programlisting>
<para>Gets the position of the given element
in the <link linkend="GSList"><type>GSList</type></link> (starting from 0).</para>
<refsect3 id="g-slist-position.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>llink</para></entry>
<entry role="parameter_description"><para>an element in the <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-position.returns" role="returns">
<title>Returns</title>
<para> the position of the element in the <link linkend="GSList"><type>GSList</type></link>,
or -1 if the element is not found</para>
</refsect3></refsect2>
<refsect2 id="g-slist-index" role="function">
<title>g_slist_index&#160;()</title>
<indexterm zone="g-slist-index"><primary sortas="slist_index">g_slist_index</primary></indexterm>
<programlisting language="C"><link linkend="gint"><returnvalue>gint</returnvalue></link>
g_slist_index (<parameter><link linkend="GSList"><type>GSList</type></link> *list</parameter>,
               <parameter><link linkend="gconstpointer"><type>gconstpointer</type></link> data</parameter>);</programlisting>
<para>Gets the position of the element containing
the given data (starting from 0).</para>
<refsect3 id="g-slist-index.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>list</para></entry>
<entry role="parameter_description"><para>a <link linkend="GSList"><type>GSList</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>data</para></entry>
<entry role="parameter_description"><para>the data to find</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-slist-index.returns" role="returns">
<title>Returns</title>
<para> the index of the element containing the data,
or -1 if the data is not found</para>
</refsect3></refsect2>

</refsect1>
<refsect1 id="glib-Singly-Linked-Lists.other_details" role="details">
<title role="details.title">Types and Values</title>
<refsect2 id="GSList" role="struct">
<title>struct GSList</title>
<indexterm zone="GSList"><primary sortas="SList">GSList</primary></indexterm>
<programlisting language="C">struct GSList {
  gpointer data;
  GSList *next;
};
</programlisting>
<para>The <link linkend="GSList"><type>GSList</type></link> struct is used for each element in the singly-linked
list.</para>
<refsect3 id="GSList.members" role="struct_members">
<title>Members</title>
<informaltable role="struct_members_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="struct_members_name" colwidth="300px"/>
<colspec colname="struct_members_description"/>
<colspec colname="struct_members_annotations" colwidth="200px"/>
<tbody>
<row role="member"><entry role="struct_member_name"><para><link linkend="gpointer"><type>gpointer</type></link>&#160;<structfield id="GSList.data">data</structfield>;</para></entry>
<entry role="struct_member_description"><para>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></para></entry>
<entry role="struct_member_annotations"></entry>
</row>
<row role="member"><entry role="struct_member_name"><para><link linkend="GSList"><type>GSList</type></link>&#160;*<structfield id="GSList.next">next</structfield>;</para></entry>
<entry role="struct_member_description"><para>contains the link to the next element in the list.</para></entry>
<entry role="struct_member_annotations"></entry>
</row>
</tbody></tgroup></informaltable>
</refsect3>
</refsect2>
<refsect2 id="g-slist-free1" role="macro" condition="since:2.10">
<title>g_slist_free1</title>
<indexterm zone="g-slist-free1" role="2.10"><primary sortas="slist_free1">g_slist_free1</primary></indexterm>
<programlisting language="C">#define             g_slist_free1</programlisting>
<para>A macro which does the same as <link linkend="g-slist-free-1"><function>g_slist_free_1()</function></link>.</para>
<para role="since">Since: <link linkend="api-index-2.10">2.10</link></para></refsect2>

</refsect1>

</refentry>
