📄 glib-double-ended-queues.html
字号:
<html xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Double-ended Queues</title><meta name="generator" content="DocBook XSL Stylesheets V1.69.0"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-data-types.html" title="GLib Data Types"><link rel="prev" href="glib-Singly-Linked-Lists.html" title="Singly-Linked Lists"><link rel="next" href="glib-Trash-Stacks.html" title="Trash Stacks"><meta name="generator" content="GTK-Doc V1.4 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Singly-Linked-Lists.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Trash-Stacks.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-Double-ended-Queues"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><span class="refentrytitle">Double-ended Queues</span></h2><p>Double-ended Queues — double-ended queue data structure.</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h> <a href="glib-Double-ended-Queues.html#GQueue">GQueue</a>;<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a>* <a href="glib-Double-ended-Queues.html#g-queue-new">g_queue_new</a> (void);void <a href="glib-Double-ended-Queues.html#g-queue-free">g_queue_free</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Basic-Types.html#gboolean">gboolean</a> <a href="glib-Double-ended-Queues.html#g-queue-is-empty">g_queue_is_empty</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Basic-Types.html#guint">guint</a> <a href="glib-Double-ended-Queues.html#g-queue-get-length">g_queue_get_length</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);void <a href="glib-Double-ended-Queues.html#g-queue-reverse">g_queue_reverse</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a>* <a href="glib-Double-ended-Queues.html#g-queue-copy">g_queue_copy</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);void <a href="glib-Double-ended-Queues.html#g-queue-foreach">g_queue_foreach</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Doubly-Linked-Lists.html#GFunc">GFunc</a> func, <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);<a href="glib-Doubly-Linked-Lists.html#GList">GList</a>* <a href="glib-Double-ended-Queues.html#g-queue-find">g_queue_find</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data);<a href="glib-Doubly-Linked-Lists.html#GList">GList</a>* <a href="glib-Double-ended-Queues.html#g-queue-find-custom">g_queue_find_custom</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data, <a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> func);void <a href="glib-Double-ended-Queues.html#g-queue-sort">g_queue_sort</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> compare_func, <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);void <a href="glib-Double-ended-Queues.html#g-queue-push-head">g_queue_push_head</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gpointer">gpointer</a> data);void <a href="glib-Double-ended-Queues.html#g-queue-push-tail">g_queue_push_tail</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gpointer">gpointer</a> data);void <a href="glib-Double-ended-Queues.html#g-queue-push-nth">g_queue_push_nth</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gpointer">gpointer</a> data, <a href="glib-Basic-Types.html#gint">gint</a> n);<a href="glib-Basic-Types.html#gpointer">gpointer</a> <a href="glib-Double-ended-Queues.html#g-queue-pop-head">g_queue_pop_head</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Basic-Types.html#gpointer">gpointer</a> <a href="glib-Double-ended-Queues.html#g-queue-pop-tail">g_queue_pop_tail</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Basic-Types.html#gpointer">gpointer</a> <a href="glib-Double-ended-Queues.html#g-queue-pop-nth">g_queue_pop_nth</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#guint">guint</a> n);<a href="glib-Basic-Types.html#gpointer">gpointer</a> <a href="glib-Double-ended-Queues.html#g-queue-peek-head">g_queue_peek_head</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Basic-Types.html#gpointer">gpointer</a> <a href="glib-Double-ended-Queues.html#g-queue-peek-tail">g_queue_peek_tail</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Basic-Types.html#gpointer">gpointer</a> <a href="glib-Double-ended-Queues.html#g-queue-peek-nth">g_queue_peek_nth</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#guint">guint</a> n);<a href="glib-Basic-Types.html#gint">gint</a> <a href="glib-Double-ended-Queues.html#g-queue-index">g_queue_index</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data);void <a href="glib-Double-ended-Queues.html#g-queue-remove">g_queue_remove</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data);void <a href="glib-Double-ended-Queues.html#g-queue-remove-all">g_queue_remove_all</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> data);void <a href="glib-Double-ended-Queues.html#g-queue-insert-before">g_queue_insert_before</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *sibling, <a href="glib-Basic-Types.html#gpointer">gpointer</a> data);void <a href="glib-Double-ended-Queues.html#g-queue-insert-after">g_queue_insert_after</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *sibling, <a href="glib-Basic-Types.html#gpointer">gpointer</a> data);void <a href="glib-Double-ended-Queues.html#g-queue-insert-sorted">g_queue_insert_sorted</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gpointer">gpointer</a> data, <a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> func, <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);void <a href="glib-Double-ended-Queues.html#g-queue-push-head-link">g_queue_push_head_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *link_);void <a href="glib-Double-ended-Queues.html#g-queue-push-tail-link">g_queue_push_tail_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *link_);void <a href="glib-Double-ended-Queues.html#g-queue-push-nth-link">g_queue_push_nth_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#gint">gint</a> n, <a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *link_);<a href="glib-Doubly-Linked-Lists.html#GList">GList</a>* <a href="glib-Double-ended-Queues.html#g-queue-pop-head-link">g_queue_pop_head_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Doubly-Linked-Lists.html#GList">GList</a>* <a href="glib-Double-ended-Queues.html#g-queue-pop-tail-link">g_queue_pop_tail_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Doubly-Linked-Lists.html#GList">GList</a>* <a href="glib-Double-ended-Queues.html#g-queue-pop-nth-link">g_queue_pop_nth_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#guint">guint</a> n);<a href="glib-Doubly-Linked-Lists.html#GList">GList</a>* <a href="glib-Double-ended-Queues.html#g-queue-peek-head-link">g_queue_peek_head_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Doubly-Linked-Lists.html#GList">GList</a>* <a href="glib-Double-ended-Queues.html#g-queue-peek-tail-link">g_queue_peek_tail_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);<a href="glib-Doubly-Linked-Lists.html#GList">GList</a>* <a href="glib-Double-ended-Queues.html#g-queue-peek-nth-link">g_queue_peek_nth_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Basic-Types.html#guint">guint</a> n);<a href="glib-Basic-Types.html#gint">gint</a> <a href="glib-Double-ended-Queues.html#g-queue-link-index">g_queue_link_index</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *link_);void <a href="glib-Double-ended-Queues.html#g-queue-unlink">g_queue_unlink</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *link_);void <a href="glib-Double-ended-Queues.html#g-queue-delete-link">g_queue_delete_link</a> (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue, <a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *link_);</pre></div><div class="refsect1" lang="en"><a name="id3125258"></a><h2>Description</h2><p>The <a href="glib-Double-ended-Queues.html#GQueue"><span class="type">GQueue</span></a> structure and its associated functions provide a standardqueue data structure. Internally, <a href="glib-Double-ended-Queues.html#GQueue"><span class="type">GQueue</span></a> uses the same data structure as <a href="glib-Doubly-Linked-Lists.html#GList"><span class="type">GList</span></a> to store elements. </p><p>The data contained in each element can be either integer values, by using oneof the<a href="glib-Type-Conversion-Macros.html" title="Type Conversion Macros">Type Conversion Macros</a>,or simply pointers to any type of data.</p><p>To create a new <a href="glib-Double-ended-Queues.html#GQueue"><span class="type">GQueue</span></a>, use <a href="glib-Double-ended-Queues.html#g-queue-new"><code class="function">g_queue_new()</code></a>.</p><p>To add elements, use <a href="glib-Double-ended-Queues.html#g-queue-push-head"><code class="function">g_queue_push_head()</code></a>, <a href="glib-Double-ended-Queues.html#g-queue-push-head-link"><code class="function">g_queue_push_head_link()</code></a>, <a href="glib-Double-ended-Queues.html#g-queue-push-tail"><code class="function">g_queue_push_tail()</code></a> and <a href="glib-Double-ended-Queues.html#g-queue-push-tail-link"><code class="function">g_queue_push_tail_link()</code></a>.</p><p>To remove elements, use <a href="glib-Double-ended-Queues.html#g-queue-pop-head"><code class="function">g_queue_pop_head()</code></a> and <a href="glib-Double-ended-Queues.html#g-queue-pop-tail"><code class="function">g_queue_pop_tail()</code></a>.</p><p>To free the entire queue, use <a href="glib-Double-ended-Queues.html#g-queue-free"><code class="function">g_queue_free()</code></a>.</p></div><div class="refsect1" lang="en"><a name="id3125414"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3125420"></a><h3><a name="GQueue"></a>GQueue</h3><a class="indexterm" name="id3125430"></a><pre class="programlisting">typedef struct { GList *head; GList *tail; guint length;} GQueue;</pre><p>Contains the public fields of a Queue.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *<em class="structfield"><code>head</code></em>;</span></td><td>a pointer to the first element of the queue.</td></tr><tr><td><span class="term"><a href="glib-Doubly-Linked-Lists.html#GList">GList</a> *<em class="structfield"><code>tail</code></em>;</span></td><td>a pointer to the last element of the queue.</td></tr><tr><td><span class="term"><a href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>length</code></em>;</span></td><td>the number of elements in the queue.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3125521"></a><h3><a name="g-queue-new"></a>g_queue_new ()</h3><a class="indexterm" name="id3125532"></a><pre class="programlisting"><a href="glib-Double-ended-Queues.html#GQueue">GQueue</a>* g_queue_new (void);</pre><p>Creates a new <a href="glib-Double-ended-Queues.html#GQueue"><span class="type">GQueue</span></a>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> a new <a href="glib-Double-ended-Queues.html#GQueue"><span class="type">GQueue</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3125586"></a><h3><a name="g-queue-free"></a>g_queue_free ()</h3><a class="indexterm" name="id3125596"></a><pre class="programlisting">void g_queue_free (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);</pre><p>Frees the memory allocated for the <a href="glib-Double-ended-Queues.html#GQueue"><span class="type">GQueue</span></a>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>queue</code></em> :</span></td><td> a <a href="glib-Double-ended-Queues.html#GQueue"><span class="type">GQueue</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3125662"></a><h3><a name="g-queue-is-empty"></a>g_queue_is_empty ()</h3><a class="indexterm" name="id3125672"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_queue_is_empty (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);</pre><p>Returns <code class="literal">TRUE</code> if the queue is empty.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>queue</code></em> :</span></td><td> a <a href="glib-Double-ended-Queues.html#GQueue"><span class="type">GQueue</span></a>.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <code class="literal">TRUE</code> if the queue is empty.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3125752"></a><h3><a name="g-queue-get-length"></a>g_queue_get_length ()</h3><a class="indexterm" name="id3125763"></a><pre class="programlisting"><a href="glib-Basic-Types.html#guint">guint</a> g_queue_get_length (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);</pre><p>Returns the number of items in <em class="parameter"><code>queue</code></em>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>queue</code></em> :</span></td><td> a <a href="glib-Double-ended-Queues.html#GQueue"><span class="type">GQueue</span></a></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> The number of items in <em class="parameter"><code>queue</code></em>.</td></tr></tbody></table></div><p>Since 2.4</p></div><hr><div class="refsect2" lang="en"><a name="id3125846"></a><h3><a name="g-queue-reverse"></a>g_queue_reverse ()</h3><a class="indexterm" name="id3125856"></a><pre class="programlisting">void g_queue_reverse (<a href="glib-Double-ended-Queues.html#GQueue">GQueue</a> *queue);</pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -