pasteit4me

C

l_main.c.c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdlib.h>
#include "l_list.h"

int main(int argc, char **argv)
{
   int *x, *y, *z;
   l_list *l;

   //create some pointers to numbers
   x = malloc(sizeof(int)); *x = 5;
   y = malloc(sizeof(int)); *y = 9;
   z = malloc(sizeof(int)); *z = 7;

   l = l_alloc(); //create a list
   //enqueue a few elements to the list
   l_enqn(l, x, y, z, z, NULL);
   //remove the duplicate z pointer
   l_uniquify(l, z);

   //example of using map to remove the y element
   l_mapt(l, int,
      if (*o == 9)
         l_map_remove(l);
   );

   //example of using map to print all elements and then free
   l_mapt(l, int, 
       printf("n = %d\n", *o);
       free(o);
   );
   l_dealloc(l);
   return 0;
}

Logo by Benalene | Syntax coloring by Pygments