Gslist is a link vertex. Its definition is as follows:
Typedef struct {
Gpointer data;
Gslist * next;
} Gslist;
Data is the location information of the vertex information (object), and next is the address information of the next vertex information, with gslist
You can perform operations such as adding, inserting, and deleting links to the vertex, such as using g_slist_append (), g_slist_prepend, use g_slist_sort () for sorting.
The following program is a simple example, using gslist as a heap example:
# Include <glib. h>
Void for_callback (gstring * string, gpointer user_data ){
If (string ){
Printf ("% s/n", string-> Str );
}
}
Int main (INT argc, char * argv []) {
Gstring * string;
Gslist * List;
Int select;
Char input [10];
List = NULL; // There is no starting point
While (true ){
Printf (
"/N please select (-1 end): (1) added to heap worker (2) values except worker end (3) show all content ");
Printf ("/N $ C> ");
Scanf ("% d", & select );
If (select =-1 ){
Break;
}
Switch (select ){
Case 1:
Printf ("/n accept input value :");
Scanf ("% s", & input );
String = g_string_new (input );
List = g_slist_prepend (list, string );
Break;
Case 2:
String = List-> data;
List = g_slist_remove (list, string );
Printf ("/n trim end value removed: % s", string-> Str );
Break;
Case 3:
G_slist_foreach (list, (gfunc) for_callback, null );
Break;
Default:
Printf ("/n select multiple variables! ");
}
}
Printf ("/N ");
G_slist_free (list );
Return 0;
}
The results of a line are as follows:
Please select option (-1 end): (1) Add to heap memory (2) exclude volume end value (3) show all content $ C> 1Inbound value: Caterpillar Please select option (-1 end): (1) Add to heap memory (2) exclude volume end value (3) show all content $ C> 1 Volume input value: momor Please select option (-1 end): (1) Add to heap memory (2) exclude volume end value (3) show all content $ C> 1 Comment input value: Bush Please select option (-1 end): (1) Add to heap memory (2) exclude volume end value (3) show all content $ C> 3 Bush Momor Caterpillar Please select option (-1 end): (1) Add to heap memory (2) exclude volume end value (3) show all content $ C> 2 Remove comment end value: Bush Please select option (-1 end): (1) Add to heap memory (2) exclude volume end value (3) show all content $ C>-1
|
Glist is a forward-to-backward relation. Its definition is as follows:
Typedef struct {
Gpointer data;
Glist * next;
Glist * Prev;
} Glist;
Prev is a function that points to the previous vertex. You can refer to Glist for its combination.
Description file.