GLib Reference Manual | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
#include <glib.h> struct GQueue; GQueue* g_queue_new (void); void g_queue_free (GQueue *queue); void g_queue_push_head (GQueue *queue, gpointer data); void g_queue_push_tail (GQueue *queue, gpointer data); gpointer g_queue_pop_head (GQueue *queue); gpointer g_queue_pop_tail (GQueue *queue); gboolean g_queue_is_empty (GQueue *queue); gpointer g_queue_peek_head (GQueue *queue); gpointer g_queue_peek_tail (GQueue *queue); void g_queue_push_head_link (GQueue *queue, GList *link); void g_queue_push_tail_link (GQueue *queue, GList *link); GList* g_queue_pop_head_link (GQueue *queue); GList* g_queue_pop_tail_link (GQueue *queue); |
The GQueue structure and its associated functions provide a standard queue data structure. Internally, GQueue uses the same data structure as GList to store elements.
The data contained in each element can be either integer values, by using one of the Type Conversion Macros, or simply pointers to any type of data.
To create a new GQueue, use g_queue_new().
To add elements, use g_queue_push_head(), g_queue_push_head_link(), g_queue_push_tail() and g_queue_push_tail_link().
To remove elements, use g_queue_pop_head() and g_queue_pop_tail().
To free the entire queue, use g_queue_free().
struct GQueue { GList *head; GList *tail; guint length; }; |
Contains the public fields of a Queue.
void g_queue_free (GQueue *queue); |
Frees the memory allocated for the GQueue.
queue : | a GQueue. |
void g_queue_push_head (GQueue *queue, gpointer data); |
Adds a new element at the head of the queue.
queue : | a GQueue. |
data : | the data for the new element. |
void g_queue_push_tail (GQueue *queue, gpointer data); |
Adds a new element at the tail of the queue.
queue : | a GQueue. |
data : | the data for the new element. |
gpointer g_queue_pop_head (GQueue *queue); |
Removes the first element of the queue.
queue : | a GQueue. |
Returns : | the data of the first element in the queue, or NULL if the queue is empty. |
gpointer g_queue_pop_tail (GQueue *queue); |
Removes the last element of the queue.
queue : | a GQueue. |
Returns : | the data of the last element in the queue, or NULL if the queue is empty. |
gboolean g_queue_is_empty (GQueue *queue); |
Returns TRUE if the queue is empty.
queue : | a GQueue. |
Returns : | TRUE if the queue is empty. |
gpointer g_queue_peek_head (GQueue *queue); |
Returns the first element of the queue.
queue : | a GQueue. |
Returns : | the data of the first element in the queue, or NULL if the queue is empty. |
gpointer g_queue_peek_tail (GQueue *queue); |
Returns the last element of the queue.
queue : | a GQueue. |
Returns : | the data of the last element in the queue, or NULL if the queue is empty. |
void g_queue_push_head_link (GQueue *queue, GList *link); |
Adds a new element at the head of the queue.
void g_queue_push_tail_link (GQueue *queue, GList *link); |
Adds a new element at the tail of the queue.
GList* g_queue_pop_head_link (GQueue *queue); |
Removes the first element of the queue.