Removed PUBLIC and PRIVATE, corrected some examples and new test
This commit is contained in:
1 parent
a9b775419d
commit
0f84d65656
39 files changed
+322
-327
No files matched your search
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#include "deque.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
DEQUE_GENERATE(d, deque, static, int)
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#include "hashmap.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
HASHMAP_GENERATE(hm, hmap, static, int, double)
|
||||
|
||||
@@ -27,7 +26,7 @@ size_t inthash(int t)
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
@@ -61,14 +60,14 @@ int main(int argc, char const *argv[])
|
||||
|
||||
for (hm_iter_to_start(&iter); !hm_iter_end(&iter); hm_iter_next(&iter))
|
||||
{
|
||||
printf("M[%2d] = { %2d : %2.2lf }\n", hm_iter_index(&iter), hm_iter_key(&iter), hm_iter_value(&iter));
|
||||
printf("HM[%2d] = { %2d : %2.2lf }\n", hm_iter_index(&iter), hm_iter_key(&iter), hm_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (hm_iter_to_end(&iter); !hm_iter_start(&iter); hm_iter_prev(&iter))
|
||||
{
|
||||
printf("M[%2d] = { %2d : %2.2lf }\n", hm_iter_index(&iter), hm_iter_key(&iter), hm_iter_value(&iter));
|
||||
printf("HM[%2d] = { %2d : %2.2lf }\n", hm_iter_index(&iter), hm_iter_key(&iter), hm_iter_value(&iter));
|
||||
}
|
||||
|
||||
hm_free(hm);
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#include "hashset.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
HASHSET_GENERATE(hs, hset, static, int)
|
||||
|
||||
@@ -27,12 +26,12 @@ size_t inthash(int t)
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// Initialize hash set and add some elements
|
||||
// Initialize hashset and add some elements
|
||||
hset *hs = hs_new(10, 0.9, intcmp, inthash);
|
||||
for (int i = 0; i < 10; i++)
|
||||
hs_insert(hs, i);
|
||||
@@ -60,14 +59,14 @@ int main(int argc, char const *argv[])
|
||||
|
||||
for (hs_iter_to_start(&iter); !hs_iter_end(&iter); hs_iter_next(&iter))
|
||||
{
|
||||
printf("S[%2d] = %2d\n", hs_iter_index(&iter), hs_iter_value(&iter));
|
||||
printf("HS[%2d] = %2d\n", hs_iter_index(&iter), hs_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (hs_iter_to_end(&iter); !hs_iter_start(&iter); hs_iter_prev(&iter))
|
||||
{
|
||||
printf("S[%2d] = %2d\n", hs_iter_index(&iter), hs_iter_value(&iter));
|
||||
printf("HS[%2d] = %2d\n", hs_iter_index(&iter), hs_iter_value(&iter));
|
||||
}
|
||||
|
||||
hs_free(hs);
|
||||
|
||||
@@ -9,11 +9,10 @@
|
||||
*/
|
||||
#include "heap.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
HEAP_GENERATE(h, heap, static, int)
|
||||
|
||||
@@ -9,20 +9,19 @@
|
||||
*/
|
||||
#include "linkedlist.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
LINKEDLIST_GENERATE(ll, linkedlist, static, int)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// Initialize list and add some elements
|
||||
linkedlist *l = ll_new();
|
||||
// Initialize linkedlist and add some elements
|
||||
linkedlist *ll = ll_new();
|
||||
for (int i = 0; i < 10; i++)
|
||||
ll_push_back(l, i);
|
||||
ll_push_back(ll, i);
|
||||
|
||||
// Initialize iterator
|
||||
linkedlist_iter iter;
|
||||
ll_iter_init(&iter, l);
|
||||
ll_iter_init(&iter, ll);
|
||||
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
@@ -53,7 +52,7 @@ int main(int argc, char const *argv[])
|
||||
printf("LL[%2d] = %2d\n", ll_iter_index(&iter), ll_iter_value(&iter));
|
||||
}
|
||||
|
||||
ll_free(l);
|
||||
ll_free(ll);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#include "list.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
LIST_GENERATE(l, list, static, int)
|
||||
|
||||
|
||||
+15
-15
@@ -7,17 +7,13 @@
|
||||
* Leonardo Vencovsky (https://github.com/LeoVen)
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "queue.h"
|
||||
#include <stdio.h>
|
||||
|
||||
QUEUE_GENERATE(q, queue, static, int)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
// Initialize queue and add some elements
|
||||
queue *q = q_new(10);
|
||||
for (int i = 0; i < 10; i++)
|
||||
@@ -30,26 +26,30 @@ int main(int argc, char const *argv[])
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
while (q_iter_next(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!q_iter_end(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", q_iter_index(&iter), q_iter_value(&iter));
|
||||
q_iter_next(&iter);
|
||||
}
|
||||
printf("\n");
|
||||
while (q_iter_prev(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!q_iter_start(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", q_iter_index(&iter), q_iter_value(&iter));
|
||||
q_iter_prev(&iter);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
for (q_iter_tostart(&iter); !q_iter_end(&iter); /**/)
|
||||
for (q_iter_to_start(&iter); !q_iter_end(&iter); q_iter_next(&iter))
|
||||
{
|
||||
q_iter_next(&iter, &r, &i);
|
||||
printf("Q[%2d] = %2d\n", i, r);
|
||||
printf("Q[%2d] = %2d\n", q_iter_index(&iter), q_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (q_iter_toend(&iter); !q_iter_start(&iter); /**/)
|
||||
for (q_iter_to_end(&iter); !q_iter_start(&iter); q_iter_prev(&iter))
|
||||
{
|
||||
q_iter_prev(&iter, &r, &i);
|
||||
printf("Q[%2d] = %2d\n", i, r);
|
||||
printf("Q[%2d] = %2d\n", q_iter_index(&iter), q_iter_value(&iter));
|
||||
}
|
||||
|
||||
q_free(q);
|
||||
|
||||
+15
-15
@@ -7,17 +7,13 @@
|
||||
* Leonardo Vencovsky (https://github.com/LeoVen)
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "stack.h"
|
||||
#include <stdio.h>
|
||||
|
||||
STACK_GENERATE(s, stack, static, int)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
// Initialize stack and add some elements
|
||||
stack *s = s_new(10);
|
||||
for (int i = 0; i < 10; i++)
|
||||
@@ -30,26 +26,30 @@ int main(int argc, char const *argv[])
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
while (s_iter_next(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!s_iter_end(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", s_iter_index(&iter), s_iter_value(&iter));
|
||||
s_iter_next(&iter);
|
||||
}
|
||||
printf("\n");
|
||||
while (s_iter_prev(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!s_iter_start(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", s_iter_index(&iter), s_iter_value(&iter));
|
||||
s_iter_prev(&iter);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
for (s_iter_tostart(&iter); !s_iter_end(&iter); /**/)
|
||||
for (s_iter_to_start(&iter); !s_iter_end(&iter); s_iter_next(&iter))
|
||||
{
|
||||
s_iter_next(&iter, &r, &i);
|
||||
printf("S[%2d] = %2d\n", i, r);
|
||||
printf("S[%2d] = %2d\n", s_iter_index(&iter), s_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (s_iter_toend(&iter); !s_iter_start(&iter); /**/)
|
||||
for (s_iter_to_end(&iter); !s_iter_start(&iter); s_iter_prev(&iter))
|
||||
{
|
||||
s_iter_prev(&iter, &r, &i);
|
||||
printf("S[%2d] = %2d\n", i, r);
|
||||
printf("S[%2d] = %2d\n", s_iter_index(&iter), s_iter_value(&iter));
|
||||
}
|
||||
|
||||
s_free(s);
|
||||
|
||||
@@ -7,58 +7,58 @@
|
||||
* Leonardo Vencovsky (https://github.com/LeoVen)
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "treemap.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
TREEMAP_GENERATE(tm, tmap, static, int, double)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
size_t i;
|
||||
int k;
|
||||
double v, varr[10] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
|
||||
double varr[10] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
|
||||
|
||||
// Initialize treemap and add some element
|
||||
tmap *tm = tm_new(intcmp);
|
||||
tmap *hm = tm_new(intcmp);
|
||||
for (int i = 0; i < 10; i++)
|
||||
tm_insert(tm, i, varr[i]);
|
||||
tm_insert(hm, i, varr[i]);
|
||||
|
||||
// Initialize iterator
|
||||
tmap_iter iter;
|
||||
tm_iter_init(&iter, tm);
|
||||
tm_iter_init(&iter, hm);
|
||||
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
while (tm_iter_next(&iter, &k, &v, &i))
|
||||
printf("S[%2d] = { %2d : %2.2lf }\n", i, k, v);
|
||||
while (!tm_iter_end(&iter))
|
||||
{
|
||||
printf("C[%2d] = { %2d : %2.2lf }\n", tm_iter_index(&iter), tm_iter_key(&iter), tm_iter_value(&iter));
|
||||
tm_iter_next(&iter);
|
||||
}
|
||||
printf("\n");
|
||||
while (tm_iter_prev(&iter, &k, &v, &i))
|
||||
printf("S[%2d] = { %2d : %2.2lf }\n", i, k, v);
|
||||
while (!tm_iter_start(&iter))
|
||||
{
|
||||
printf("C[%2d] = { %2d : %2.2lf }\n", tm_iter_index(&iter), tm_iter_key(&iter), tm_iter_value(&iter));
|
||||
tm_iter_prev(&iter);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
for (tm_iter_tostart(&iter); !tm_iter_end(&iter); /**/)
|
||||
for (tm_iter_to_start(&iter); !tm_iter_end(&iter); tm_iter_next(&iter))
|
||||
{
|
||||
tm_iter_next(&iter, &k, &v, &i);
|
||||
printf("M[%2d] = { %2d : %2.2lf }\n", i, k, v);
|
||||
printf("TM[%2d] = { %2d : %2.2lf }\n", tm_iter_index(&iter), tm_iter_key(&iter), tm_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (tm_iter_toend(&iter); !tm_iter_start(&iter); /**/)
|
||||
for (tm_iter_to_end(&iter); !tm_iter_start(&iter); tm_iter_prev(&iter))
|
||||
{
|
||||
tm_iter_prev(&iter, &k, &v, &i);
|
||||
printf("M[%2d] = { %2d : %2.2lf }\n", i, k, v);
|
||||
printf("TM[%2d] = { %2d : %2.2lf }\n", tm_iter_index(&iter), tm_iter_key(&iter), tm_iter_value(&iter));
|
||||
}
|
||||
|
||||
tm_free(tm);
|
||||
tm_free(hm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -7,22 +7,18 @@
|
||||
* Leonardo Vencovsky (https://github.com/LeoVen)
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "treeset.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
TREESET_GENERATE(ts, tset, static, int)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
// Initialize treeset and add some elements
|
||||
tset *ts = ts_new(intcmp);
|
||||
for (int i = 0; i < 10; i++)
|
||||
@@ -35,26 +31,30 @@ int main(int argc, char const *argv[])
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
while (ts_iter_next(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!ts_iter_end(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", ts_iter_index(&iter), ts_iter_value(&iter));
|
||||
ts_iter_next(&iter);
|
||||
}
|
||||
printf("\n");
|
||||
while (ts_iter_prev(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!ts_iter_start(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", ts_iter_index(&iter), ts_iter_value(&iter));
|
||||
ts_iter_prev(&iter);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
for (ts_iter_tostart(&iter); !ts_iter_end(&iter); /**/)
|
||||
for (ts_iter_to_start(&iter); !ts_iter_end(&iter); ts_iter_next(&iter))
|
||||
{
|
||||
ts_iter_next(&iter, &r, &i);
|
||||
printf("S[%2d] = %2d\n", i, r);
|
||||
printf("TS[%2d] = %2d\n", ts_iter_index(&iter), ts_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (ts_iter_toend(&iter); !ts_iter_start(&iter); /**/)
|
||||
for (ts_iter_to_end(&iter); !ts_iter_start(&iter); ts_iter_prev(&iter))
|
||||
{
|
||||
ts_iter_prev(&iter, &r, &i);
|
||||
printf("S[%2d] = %2d\n", i, r);
|
||||
printf("TS[%2d] = %2d\n", ts_iter_index(&iter), ts_iter_value(&iter));
|
||||
}
|
||||
|
||||
ts_free(ts);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Other examples
|
||||
|
||||
* book_store - A book store where its books are loaded onto a list from a csv file. The newly added ones go to a queue of featured books where old ones are removed to give place to new ones. You can find a book by looking up its ISBN using a treemap or traversing the treemap and find all ISBNs of a corresponding title.
|
||||
* separate_header_source - Example of how to used `PUBLIC` and `PRIVATE` parameters.
|
||||
* for_each.c - Using the `FOR_EACH`.
|
||||
* separate_header_source - Example of how to compile the header and source separately.
|
||||
* for_each.c - Using the `FOR_EACH` macro.
|
||||
@@ -9,11 +9,11 @@
|
||||
#include "book.c"
|
||||
#include "random.c"
|
||||
|
||||
COLLECTION_GENERATE(LIST, PUBLIC, l, list, , , book *)
|
||||
COLLECTION_GENERATE(LIST, PUBLIC, il, intlist, , , int)
|
||||
COLLECTION_GENERATE(QUEUE, PUBLIC, q, queue, , , book *)
|
||||
COLLECTION_GENERATE(TREEMAP, PUBLIC, map, map, , int, char *)
|
||||
COLLECTION_GENERATE(TREESET, PUBLIC, set, set, , , char *)
|
||||
COLLECTION_GENERATE(LIST, l, list, , , book *)
|
||||
COLLECTION_GENERATE(LIST, il, intlist, , , int)
|
||||
COLLECTION_GENERATE(QUEUE, q, queue, , , book *)
|
||||
COLLECTION_GENERATE(TREEMAP, map, map, , int, char *)
|
||||
COLLECTION_GENERATE(TREESET, set, set, , , char *)
|
||||
|
||||
list *load(void);
|
||||
void shuffle(list *l);
|
||||
@@ -48,7 +48,9 @@ int main(int argc, char const *argv[])
|
||||
set *counter = set_new(chrcmp);
|
||||
|
||||
// Add everything to its place.
|
||||
FOR_EACH(l, list, book *, books, {
|
||||
FOR_EACH(l, list, books, {
|
||||
book *value = l_iter_value(&iter);
|
||||
|
||||
// Keep the last added elements
|
||||
if (q_count(shelf) > 7)
|
||||
{
|
||||
@@ -64,7 +66,8 @@ int main(int argc, char const *argv[])
|
||||
printf("Library Size: %d\n", map_count(library));
|
||||
printf("Unique book titles: %d\n\n", set_count(counter));
|
||||
printf("Showcase Books:\n");
|
||||
FOR_EACH(q, queue, book *, shelf, {
|
||||
FOR_EACH(q, queue, shelf, {
|
||||
book *value = q_iter_value(&iter);
|
||||
printf("[ %d : %-45s ]\n", value->isbn, value->name);
|
||||
})
|
||||
printf("\n");
|
||||
@@ -113,13 +116,16 @@ int main(int argc, char const *argv[])
|
||||
|
||||
intlist *search_list = il_new(32);
|
||||
|
||||
FOR_EACH_MAP(map, map, int, char *, library, {
|
||||
FOR_EACH(map, map, library, {
|
||||
int key = map_iter_key(&iter);
|
||||
char *value = map_iter_value(&iter);
|
||||
|
||||
if (chrcmp(buffer, value) == 0)
|
||||
il_push_back(search_list, key);
|
||||
})
|
||||
|
||||
FOR_EACH(il, intlist, int, search_list, {
|
||||
printf("[ %d ]\n", value);
|
||||
FOR_EACH(il, intlist, search_list, {
|
||||
printf("[ %d ]\n", il_iter_value(&iter));
|
||||
})
|
||||
|
||||
il_free(search_list);
|
||||
@@ -127,9 +133,13 @@ int main(int argc, char const *argv[])
|
||||
}
|
||||
|
||||
// Free all memory used by struct book
|
||||
FOR_EACH(l, list, book *, books, {
|
||||
free(value->name);
|
||||
free(value);
|
||||
FOR_EACH(l, list, books, {
|
||||
book *b = l_iter_value(&iter);
|
||||
|
||||
if (b)
|
||||
free(b->name);
|
||||
|
||||
free(b);
|
||||
})
|
||||
|
||||
l_free(books);
|
||||
|
||||
+25
-13
@@ -4,16 +4,16 @@
|
||||
#include "macro_collections.h"
|
||||
|
||||
// Create containers to use only in this file
|
||||
COLLECTION_GENERATE(LIST, PUBLIC, l, list, static, , int)
|
||||
COLLECTION_GENERATE(LINKEDLIST, PUBLIC, ll, llist, static, , int)
|
||||
COLLECTION_GENERATE(STACK, PUBLIC, s, stack, static, , int)
|
||||
COLLECTION_GENERATE(QUEUE, PUBLIC, q, queue, static, , int)
|
||||
COLLECTION_GENERATE(DEQUE, PUBLIC, d, deque, static, , int)
|
||||
COLLECTION_GENERATE(TREESET, PUBLIC, ts, tset, static, , int)
|
||||
COLLECTION_GENERATE(LIST, l, list, static, , int)
|
||||
COLLECTION_GENERATE(LINKEDLIST, ll, llist, static, , int)
|
||||
COLLECTION_GENERATE(STACK, s, stack, static, , int)
|
||||
COLLECTION_GENERATE(QUEUE, q, queue, static, , int)
|
||||
COLLECTION_GENERATE(DEQUE, d, deque, static, , int)
|
||||
COLLECTION_GENERATE(TREESET, ts, tset, static, , int)
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
@@ -58,7 +58,9 @@ int main(int argc, char const *argv[])
|
||||
// - value : the elements that changes with each iteration
|
||||
// - index : iteration index (first iteration is 0 and last is count - 1)
|
||||
// - iter : iterator struct
|
||||
FOR_EACH(l, list, int, l, {
|
||||
FOR_EACH(l, list, l, {
|
||||
int value = l_iter_value(&iter);
|
||||
size_t index = l_iter_index(&iter);
|
||||
if (index == 0)
|
||||
printf("[ %d, ", value);
|
||||
else if (index == iter.target->count - 1)
|
||||
@@ -67,7 +69,9 @@ int main(int argc, char const *argv[])
|
||||
printf("%d, ", value);
|
||||
})
|
||||
|
||||
FOR_EACH(s, stack, int, s, {
|
||||
FOR_EACH(s, stack, s, {
|
||||
int value = s_iter_value(&iter);
|
||||
size_t index = s_iter_index(&iter);
|
||||
if (index == 0)
|
||||
printf("[ %d, ", value);
|
||||
else if (index == iter.target->count - 1)
|
||||
@@ -76,7 +80,9 @@ int main(int argc, char const *argv[])
|
||||
printf("%d, ", value);
|
||||
})
|
||||
|
||||
FOR_EACH(q, queue, int, q, {
|
||||
FOR_EACH(q, queue, q, {
|
||||
int value = q_iter_value(&iter);
|
||||
size_t index = q_iter_index(&iter);
|
||||
if (index == 0)
|
||||
printf("[ %d, ", value);
|
||||
else if (index == iter.target->count - 1)
|
||||
@@ -85,7 +91,9 @@ int main(int argc, char const *argv[])
|
||||
printf("%d, ", value);
|
||||
})
|
||||
|
||||
FOR_EACH(d, deque, int, d, {
|
||||
FOR_EACH(d, deque, d, {
|
||||
int value = d_iter_value(&iter);
|
||||
size_t index = d_iter_index(&iter);
|
||||
if (index == 0)
|
||||
printf("[ %d, ", value);
|
||||
else if (index == iter.target->count - 1)
|
||||
@@ -94,7 +102,9 @@ int main(int argc, char const *argv[])
|
||||
printf("%d, ", value);
|
||||
})
|
||||
|
||||
FOR_EACH(ll, llist, int, ll, {
|
||||
FOR_EACH(ll, llist, ll, {
|
||||
int value = ll_iter_value(&iter);
|
||||
size_t index = ll_iter_index(&iter);
|
||||
if (index == 0)
|
||||
printf("[ %d, ", value);
|
||||
else if (index == iter.target->count - 1)
|
||||
@@ -103,7 +113,9 @@ int main(int argc, char const *argv[])
|
||||
printf("%d, ", value);
|
||||
})
|
||||
|
||||
FOR_EACH(ts, tset, int, ts, {
|
||||
FOR_EACH(ts, tset, ts, {
|
||||
int value = ts_iter_value(&iter);
|
||||
size_t index = ts_iter_index(&iter);
|
||||
if (index == 0)
|
||||
printf("[ %d, ", value);
|
||||
else if (index == iter.target->count - 1)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "containers.h"
|
||||
|
||||
COLLECTION_GENERATE_SOURCE(LIST, PUBLIC, il, int_list, , , int)
|
||||
COLLECTION_GENERATE_SOURCE(STACK, PRIVATE, cs, char_stack, , , char)
|
||||
COLLECTION_GENERATE_SOURCE(QUEUE, PUBLIC, queue, index_queue, , , size_t)
|
||||
COLLECTION_GENERATE_SOURCE(DEQUE, PUBLIC, dq, deque, , , int)
|
||||
COLLECTION_GENERATE_SOURCE(LIST, il, int_list, , , int)
|
||||
COLLECTION_GENERATE_SOURCE(STACK, cs, char_stack, , , char)
|
||||
COLLECTION_GENERATE_SOURCE(QUEUE, queue, index_queue, , , size_t)
|
||||
COLLECTION_GENERATE_SOURCE(DEQUE, dq, deque, , , int)
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "macro_collections.h"
|
||||
|
||||
COLLECTION_GENERATE_HEADER(LIST, PUBLIC, il, int_list, , , int)
|
||||
COLLECTION_GENERATE_HEADER(STACK, PRIVATE, cs, char_stack, , , char)
|
||||
COLLECTION_GENERATE_HEADER(QUEUE, PUBLIC, queue, index_queue, , , size_t)
|
||||
COLLECTION_GENERATE_HEADER(DEQUE, PUBLIC, dq, deque, , , int)
|
||||
COLLECTION_GENERATE_HEADER(LIST, il, int_list, , , int)
|
||||
COLLECTION_GENERATE_HEADER(STACK, cs, char_stack, , , char)
|
||||
COLLECTION_GENERATE_HEADER(QUEUE, queue, index_queue, , , size_t)
|
||||
COLLECTION_GENERATE_HEADER(DEQUE, dq, deque, , , int)
|
||||
@@ -184,9 +184,8 @@ int main(void)
|
||||
il_push_back(integers, i);
|
||||
|
||||
int sum = 0;
|
||||
FOR_EACH(il, int_list, int, integers, {
|
||||
printf("%d, ", value);
|
||||
sum += value;
|
||||
FOR_EACH(il, int_list, integers, {
|
||||
sum += il_iter_value(&iter);
|
||||
})
|
||||
|
||||
printf("\n\nSUM: %d\n", sum);
|
||||
@@ -255,8 +254,8 @@ int main(void)
|
||||
|
||||
int sum3 = 0;
|
||||
|
||||
FOR_EACH(dq, deque, int, d, {
|
||||
sum3 += value;
|
||||
FOR_EACH(dq, deque, d, {
|
||||
sum3 += dq_iter_value(&iter);
|
||||
})
|
||||
|
||||
printf("Deque sum: %d\n", sum3);
|
||||
|
||||
Reference in new issue
Block a user