#include #include #include #include "gqueue.h" #define MAX_SIZE 5 static void usage(int argc, char **argv) { if (argc != 3) { printf("Usage: %s \n", argv[0]); exit(1); } } static void delete_list(void *item) { gq_go_end(item); do { gq_go_backward(item); gq_delete(item); } while (!gq_at_beginning(item)); } void main(int argc, char **argv) { int n; int i; int j; gqueue q; gqueue q_tmp; usage(argc, argv); n = atoi(argv[1]); srand(atoi(argv[2])); q = gq_create(); for (i = 0; i < n; ++i) { div_t tmp_size = div(rand(),MAX_SIZE); q_tmp = gq_create(); for (j = 0; j < tmp_size.rem + 1; ++j) { int tmp = rand(); gq_insert (q_tmp, (void *)tmp); } gq_insert(q, (void *)q_tmp); } for (gq_go_beginning(q); !gq_at_end(q); gq_go_forward(q)) { q_tmp = (gqueue)gq_get(q); for (gq_go_beginning(q_tmp); !gq_at_end(q_tmp); gq_go_forward(q_tmp)) { printf("%d ", (int)gq_get(q_tmp)); } printf("\n"); } for (gq_go_beginning(q); !gq_at_end(q); gq_go_forward(q)) { q_tmp = (gqueue)gq_get(q); delete_list(q_tmp); } delete_list(q); assert(gq_empty(q)); gq_destroy(q); } /* test-gqueue2 10 2 1495354192 671064393 846338638 1775750268 1964509445 1826196826 2131965032 1704276097 2048075046 819762535 941305620 603745714 1167270147 1057368192 46117630 43829855 115690668 1174814069 1960837386 1085310872 1275739121 1017095767 854754628 2055710562 1485721843 582187049 1304221614 673921244 */