Skip to content

Commit

Permalink
[example] iterator example added
Browse files Browse the repository at this point in the history
  • Loading branch information
lvntky committed Aug 11, 2024
1 parent 7c45683 commit 798f04b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/cc_vector_e1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This is the iterator example
#define CC_VECTOR_IMPLEMENTATION
#include "../include/ccontainer/cc_vector.h"

int main()
{
cc_vector_t *vector = cc_vector_create(10);

int values[] = { 1, 2, 3, 4, 5 };
for (int i = 0; i < 5; ++i) {
cc_vector_push_back(vector, &values[i]);
}

cc_vector_iterator_t iter = cc_vector_iterator_begin(vector);
void *value;
while ((value = cc_vector_iterator_next(&iter)) != NULL) {
printf("%d ", *(int *)value);
}

cc_vector_free(vector);
return 0;
}

0 comments on commit 798f04b

Please sign in to comment.