### Struct

# GLib List

since: 2.0

#### Description

    struct GList {
      gpointer data;
      GList* next;
      GList* prev;
    }

The `GList` struct is used for each element in a doubly-linked list.

###### Structure members

`data`

  Holds the element’s data, which can be a pointer to any kind of data, or any integer value using the [Type Conversion Macros][glib-Type-Conversion-Macros]

`next`

  Contains the link to the next element in the list.

`prev`

  Contains the link to the previous element in the list.

Available since: 2.0

#### Functions

###### g_list_alloc

Allocates space for one `GList` element. It is called by g_list_append(), g_list_prepend(), `g_list_insert()` and `g_list_insert_sorted()` and so is rarely used on its own.

since: 2.0

###### g_list_append

Adds a new element on to the end of the list.

since: 2.0

###### g_list_concat

Adds the second `GList` onto the end of the first `GList`. Note that the elements of the second `GList` are not copied. They are used directly.

since: 2.0

###### g_list_copy

Copies a `GList`.

since: 2.0

###### g_list_copy_deep

Makes a full (deep) copy of a `GList`.

since: 2.34

###### g_list_delete_link

Removes the node link_ from the list and frees it. Compare this to `g_list_remove_link()` which removes the node without freeing it.

since: 2.0

###### g_list_find

Finds the element in a `GList` which contains the given data.

since: 2.0

###### g_list_find_custom

Finds an element in a `GList`, 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 #gconstpointer arguments, the `GList` element’s data as the first argument and the given user data.

since: 2.0

###### g_list_first

Gets the first element in a `GList`.

since: 2.0

###### g_list_foreach

Calls a function for each element of a `GList`.

since: 2.0

###### g_list_free

Frees all of the memory used by a `GList`. The freed elements are returned to the slice allocator.

since: 2.0

###### g_list_free_1

Frees one `GList` element, but does not update links from the next and previous elements in the list, so you should not call this function on an element that is currently part of a list.

since: 2.0

###### g_list_free_full

Convenience method, which frees all the memory used by a `GList`, and calls `free_func` on every element’s data.

since: 2.28

###### g_list_index

Gets the position of the element containing the given data (starting from 0).

since: 2.0

###### g_list_insert

Inserts a new element into the list at the given position.

since: 2.0

###### g_list_insert_before

Inserts a new element into the list before the given position.

since: 2.0

###### g_list_insert_before_link

Inserts `link_` into the list before the given position.

since: 2.62

###### g_list_insert_sorted

Inserts a new element into the list, using the given comparison function to determine its position.

since: 2.0

###### g_list_insert_sorted_with_data

Inserts a new element into the list, using the given comparison function to determine its position.

since: 2.10

###### g_list_last

Gets the last element in a `GList`.

since: 2.0

###### g_list_length

Gets the number of elements in a `GList`.

since: 2.0

###### g_list_nth

Gets the element at the given position in a `GList`.

since: 2.0

###### g_list_nth_data

Gets the data of the element at the given position.

since: 2.0

###### g_list_nth_prev

Gets the element `n` places before `list`.

since: 2.0

###### g_list_pop_allocator

No description available.

since: 2.0

###### g_list_position

Gets the position of the given element in the `GList` (starting from 0).

since: 2.0

###### g_list_prepend

Prepends a new element on to the start of the list.

since: 2.0

###### g_list_push_allocator

No description available.

since: 2.0

###### g_list_remove

Removes an element from a `GList`. If two elements contain the same data, only the first is removed. If none of the elements contain the data, the `GList` is unchanged.

since: 2.0

###### g_list_remove_all

Removes all list nodes with data equal to `data`. Returns the new head of the list. Contrast with `g_list_remove()` which removes only the first node matching the given data.

since: 2.0

###### g_list_remove_link

Removes an element from a `GList`, without freeing the element. The removed element’s prev and next links are set to `NULL`, so that it becomes a self-contained list with one element.

since: 2.0

###### g_list_reverse

Reverses a `GList`. It simply switches the next and prev pointers of each element.

since: 2.0

###### g_list_sort

Sorts a `GList` using the given comparison function. The algorithm used is a stable sort.

since: 2.0

###### g_list_sort_with_data

Like g_list_sort(), but the comparison function accepts a user data argument.

since: 2.0