Demo of how to use the z88dk adt p_forward_list
#include <stdio.h>
#include <stdint.h> // standard names for ints with no ambiguity
#include <adt/p_forward_list.h>
static p_forward_list_t src;
typedef struct
{
void *next;
uint8_t v;
} item_t;
int main()
{
uint8_t l;
item_t item1;
item_t item2;
item_t item3;
item1.v = 1;
item2.v = 2;
item3.v = 3;
item_t *item_ptr;
p_forward_list_init(&src);
printf("Push 1, 2, 3 to front\n");
p_forward_list_push_front(&src,&item1);
p_forward_list_push_front(&src,&item2);
p_forward_list_push_front(&src,&item3);
l = p_forward_list_size(&src);
printf("List length = %d\n", l);
printf("Read items from list\n");
for (item_ptr = p_forward_list_front(&src); item_ptr; item_ptr = p_forward_list_next(item_ptr))
{
printf("Item = %d\n", item_ptr->v);
}
printf("Clear list\n");
p_forward_list_clear(&src);
l = p_forward_list_size(&src);
printf("List length = %d\n", l);
printf("Push 1, 2, 3 to back\n");
p_forward_list_push_back(&src,&item1);
p_forward_list_push_back(&src,&item2);
p_forward_list_push_back(&src,&item3);
for (item_ptr = p_forward_list_front(&src); item_ptr; item_ptr = p_forward_list_next(item_ptr))
{
printf("Item = %d\n", item_ptr->v);
}
printf("Remove 2\n");
p_forward_list_remove(&src,&item2);
l = p_forward_list_size(&src);
printf("List length = %d\n", l);
printf("Read items from list\n");
for (item_ptr = p_forward_list_front(&src); item_ptr; item_ptr = p_forward_list_next(item_ptr))
{
printf("Item = %d\n", item_ptr->v);
}
while(1)
{
}
return 0;
}
No comments:
Post a Comment