⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-doublylinkedlists.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
字号:
<HTML><HEAD><TITLE>Doubly Linked Lists</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="GLib"HREF="ch-glib.html"><LINKREL="PREVIOUS"TITLE="GLib"HREF="ch-glib.html"><LINKREL="NEXT"TITLE="Singly Linked Lists"HREF="sec-singlylinkedlists.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="ch-glib.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 22. GLib</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-singlylinkedlists.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-DOUBLYLINKEDLISTS">22.2. Doubly Linked Lists</A></H1><P>The following functions are used to create, manage, and destroystandard doubly linked lists. Each element in the list contains apiece of data, together with pointers which link to the previous andnext elements in the list. This enables easy movement in eitherdirection through the list. The data item is of type "gpointer",which means the data can be a pointer to your real data or (throughcasting) a numeric value (but do not assume that int and gpointer havethe same size!). These routines internally allocate list elements inblocks, which is more efficient than allocating elements individually.</P><P>There is no function to specifically create a list. Instead, simplycreate a variable of type GList* and set its value to NULL; NULL isconsidered to be the empty list.</P><P>To add elements to a list, use the g_list_append(), g_list_prepend(),g_list_insert(), or g_list_insert_sorted() routines. In all casesthey accept a pointer to the beginning of the list, and return the(possibly changed) pointer to the beginning of the list. Thus, forall of the operations that add or remove elements, be sure to save thereturned value!</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GList *g_list_append( GList    *list,                      gpointer  data );</PRE></TD></TR></TABLE><P>This adds a new element (with value <TTCLASS="LITERAL">data</TT>) onto the end of thelist.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GList *g_list_prepend( GList    *list,                       gpointer  data );</PRE></TD></TR></TABLE><P>This adds a new element (with value <TTCLASS="LITERAL">data</TT>) to the beginning of thelist.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GList *g_list_insert( GList    *list,                      gpointer  data,                      gint      position );</PRE></TD></TR></TABLE><P>This inserts a new element (with value data) into the list at thegiven position. If position is 0, this is just like g_list_prepend();if position is less than 0, this is just like g_list_append().</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GList *g_list_remove( GList    *list,                      gpointer  data );</PRE></TD></TR></TABLE><P>This removes the element in the list with the value <TTCLASS="LITERAL">data</TT>;if the element isn't there, the list is unchanged.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void g_list_free( GList *list );</PRE></TD></TR></TABLE><P>This frees all of the memory used by a GList. If the list elementsrefer to dynamically-allocated memory, then they should be freedfirst.</P><P>There are many other GLib functions that support doubly linked lists;see the glib documentation for more information.  Here are a few ofthe more useful functions' signatures:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">  GList *g_list_remove_link( GList *list,                           GList *link );GList *g_list_reverse( GList *list );GList *g_list_nth( GList *list,                   gint   n );			   GList *g_list_find( GList    *list,                    gpointer  data );GList *g_list_last( GList *list );GList *g_list_first( GList *list );gint g_list_length( GList *list );void g_list_foreach( GList    *list,                     GFunc     func,                     gpointer  user_data );</PRE></TD></TR></TABLE></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="ch-glib.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sec-singlylinkedlists.html">Next &#62;&#62;&#62;</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">GLib</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-glib.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Singly Linked Lists</TD></TR></TABLE></DIV>        </td>    </tr></table>  </td>  </tr></table></body></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -