gdsl
1.8
|
This is an example of how to use _gdsl_list module.
/* * This file is part of the Generic Data Structures Library (GDSL). * Copyright (C) 1998-2018 Nicolas Darnis <ndarnis@free.fr>. * * GDSL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GDSL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GDSL. If not, see <http://www.gnu.org/licenses/>. * * * GDSL - Generic Data Structures Library * $RCSfile: main_lllist.c,v $ * $Revision: 1.13 $ * $Date: 2015/02/17 12:33:16 $ */ #include <config.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "_gdsl_list.h" #include "_strings.h" static void my_node_write (const _gdsl_node_t n, FILE* file, void* data) { gdsl_element_t e = _gdsl_node_get_content (n); if (data == NULL) { fprintf (file, "%s", (char*) e); } else { fprintf (file, "%s%s", (char*) e, (char*) data); } } static int my_node_map (const _gdsl_node_t n, void* data) { my_node_write (n, stdout, data); return GDSL_MAP_CONT; } int main (void) { _gdsl_list_t a = _gdsl_list_alloc (alloc_string ("a")); _gdsl_list_t b = _gdsl_list_alloc (alloc_string ("b")); _gdsl_list_t c = _gdsl_list_alloc (alloc_string ("c")); _gdsl_list_link (a, b); _gdsl_list_link (b, c); printf ("WRITE (%ld elements):\n", _gdsl_list_get_size (a)); _gdsl_list_write (a, my_node_write, stdout, NULL); printf ("\n\nDUMP:\n"); _gdsl_list_dump (a, my_node_write, stdout, NULL); printf ("\nWRITE XML:\n"); _gdsl_list_write_xml (a, my_node_write, stdout, NULL); printf ("\nMAP FORWARD:\n"); _gdsl_list_map_forward (a, my_node_map, NULL); printf ("\n"); printf ("\nMAP BACKWARD:\n"); _gdsl_list_map_backward (a, my_node_map, NULL); printf ("\n"); _gdsl_list_free (a, free_string); exit (EXIT_SUCCESS); }