GRU linked list example
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
void check_val(
const void *nodedata,
void *data) {
bool *exist = (bool *) data;
uint32_t value = (*(uint32_t *) nodedata);
if (value == 32) {
*exist = true;
}
}
int main(
int argc,
char **argv) {
uint32_t list_size = 256;
if (!list) {
printf(
"Unable to create a new list: %s\n", status.
message);
return EXIT_FAILURE;
}
#if !defined(_WIN32) && !defined(_WIN64)
uint32_t tmp[list_size];
#else
uint32_t tmp[256];
#endif
for (uint32_t i = 0; i < list_size; i++) {
tmp[i] = i;
}
if (count != 256) {
printf("Unexpected list size: %i != %i\n", count, list_size);
goto e_exit;
}
if (node64 == NULL) {
printf("The node does not exist\n");
goto e_exit;
}
if (value != 64) {
printf(
"The value of the node does not match the expected: %i != %i\n", value, 64);
goto e_exit;
}
uint32_t new_value = 444;
if (count != 257) {
printf("Unexpected list size: %i != %i\n", count, list_size + 1);
goto e_exit;
}
if (count != 254) {
printf("Unexpected list size: %i != %i\n", count, 254);
goto e_exit;
}
bool exist = false;
if (!exist) {
printf("Value 32 should be present on the list");
goto e_exit;
}
if (list != NULL) {
printf("List incorrectly destroyed\n");
goto e_exit;
}
return EXIT_SUCCESS;
e_exit:
if (list != NULL) {
printf("List incorrectly destroyed\n");
}
return EXIT_FAILURE;
}