C
ProgrammingNow, both datatypes can be combined to build complex algorithms as illustrated below:
GNode* build(GString* val, char deep, GList* visited) {
GNode* node = g_node_new(val);
if (deep>0) {
for (int i=0; i<MAXI; i++) {
if (g_list_index(visited,GINT_TO_POINTER(i))==-1) {
GString* newval = g_string_new(val->str);
g_string_append_c(newval,i+'0');
GList* newvisited = g_list_copy(visited);
newvisited = g_list_append(newvisited,GINT_TO_POINTER(i));
g_node_append(node,build(newval,deep-1,newvisited));
}
}
}
return node;
}
void main() {
GNode* root = build(g_string_new(""),MAXI,NULL);
g_node_traverse(root, G_LEVEL_ORDER, G_TRAVERSE_LEAVES,-1,prn,NULL);
g_print("\n");
}