Sixth update on iterators - LINKEDLIST

This commit is contained in:
Leonardo committed 2019-05-15 18:49:40 -03:00
1 parent 918b73ad51
commit 812d0240e3
11 files changed
+382 -136

No files matched your search

+1 -1
View File
@@ -7,9 +7,9 @@
* Leonardo Vencovsky (https://github.com/LeoVen)
*
*/
#include "deque.h"
#include <stdio.h>
#include <stdlib.h>
#include "deque.h"
DEQUE_GENERATE(d, deque, static, int)
+1 -1
View File
@@ -7,9 +7,9 @@
* Leonardo Vencovsky (https://github.com/LeoVen)
*
*/
#include "hashmap.h"
#include <stdio.h>
#include <stdlib.h>
#include "hashmap.h"
HASHMAP_GENERATE(hm, hmap, static, int, double)
+1 -1
View File
@@ -7,9 +7,9 @@
* Leonardo Vencovsky (https://github.com/LeoVen)
*
*/
#include "hashset.h"
#include <stdio.h>
#include <stdlib.h>
#include "hashset.h"
HASHSET_GENERATE(hs, hset, static, int)
+1 -1
View File
@@ -7,9 +7,9 @@
* Leonardo Vencovsky (https://github.com/LeoVen)
*
*/
#include "heap.h"
#include <stdio.h>
#include <stdlib.h>
#include "heap.h"
int intcmp(int a, int b)
{
+22 -21
View File
@@ -7,52 +7,53 @@
* Leonardo Vencovsky (https://github.com/LeoVen)
*
*/
#include "linkedlist.h"
#include <stdio.h>
#include <stdlib.h>
#include "linkedlist.h"
LINKEDLIST_GENERATE(ll, linked, static, int)
LINKEDLIST_GENERATE(ll, linkedlist, static, int)
int main(int argc, char const *argv[])
{
size_t i;
int r;
// Initialize linked list and add some elements
linked *ll = ll_new();
// Initialize list and add some elements
linkedlist *l = ll_new();
for (int i = 0; i < 10; i++)
ll_push_back(ll, i);
ll_push_back(l, i);
// Initialize iterator
linked_iter iter;
ll_iter_init(&iter, ll);
linkedlist_iter iter;
ll_iter_init(&iter, l);
// Make the iterator go back and forward
for (int j = 0; j < 4; j++)
{
while (ll_iter_next(&iter, &r, &i))
printf("C[%2d] = %2d\n", i, r);
while (!ll_iter_end(&iter))
{
printf("C[%2d] = %2d\n", ll_iter_index(&iter), ll_iter_value(&iter));
ll_iter_next(&iter);
}
printf("\n");
while (ll_iter_prev(&iter, &r, &i))
printf("C[%2d] = %2d\n", i, r);
while (!ll_iter_start(&iter))
{
printf("C[%2d] = %2d\n", ll_iter_index(&iter), ll_iter_value(&iter));
ll_iter_prev(&iter);
}
printf("\n\n");
}
for (ll_iter_tostart(&iter); !ll_iter_end(&iter); /**/)
for (ll_iter_to_start(&iter); !ll_iter_end(&iter); ll_iter_next(&iter))
{
ll_iter_next(&iter, &r, &i);
printf("LL[%2d] = %2d\n", i, r);
printf("LL[%2d] = %2d\n", ll_iter_index(&iter), ll_iter_value(&iter));
}
printf("\n");
for (ll_iter_toend(&iter); !ll_iter_start(&iter); /**/)
for (ll_iter_to_end(&iter); !ll_iter_start(&iter); ll_iter_prev(&iter))
{
ll_iter_prev(&iter, &r, &i);
printf("LL[%2d] = %2d\n", i, r);
printf("LL[%2d] = %2d\n", ll_iter_index(&iter), ll_iter_value(&iter));
}
ll_free(ll);
ll_free(l);
return 0;
}
+1 -4
View File
@@ -7,17 +7,14 @@
* Leonardo Vencovsky (https://github.com/LeoVen)
*
*/
#include "list.h"
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
LIST_GENERATE(l, list, static, int)
int main(int argc, char const *argv[])
{
size_t i;
int r;
// Initialize list and add some elements
list *l = l_new(10);
for (int i = 0; i < 10; i++)