/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include #include #include "../include/list.h" typedef vtype_list list_t; int print_value(vtype_variable value, ssize_t index, void* data) { const char *n = data; switch (value.type) { default: abort(); case VTYPE_INT32: printf("%s %d (index: %ld)\n", n, *(vtype_int32*)value.pointer, index); break; case VTYPE_FLOAT: printf("%s %f (index: %ld)\n", n, *(vtype_float*)value.pointer, index); break; } return 0; } int main(int argc, char** argv) { list_t list; vtype_float fl = 0.0; list_init(&list); for (vtype_int32 i = 0; i < 28; ++i) { if (i%2) { list_push_back(&list, i); } else { list_push_back(&list, fl); fl += 0.05; } } list_get_by_index(&list, 13, "Get value:", print_value); list_pop_by_index(&list, 18, "Pop value:", print_value); list_foreach(&list, "Foreach loop:", print_value); list_free(&list); }