Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "./vector.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- VECTOR_GEN(long);
- typedef struct vector_long v_long;
- int main()
- {
- srand(time(NULL));
- v_long example;
- vt_long.init(&example);
- for (size_t i = 1; i <= 15; i++)
- vt_long.push_back(&example, i);
- // begin, at and end return pointers, front and back return values
- long *begin = vt_long.begin(&example);
- size_t index = 0;
- while (begin != vt_long.end(&example)) {
- printf("index %ld: %ld\n", index, *begin);
- index++;
- begin++;
- }
- while (!vt_long.empty(&example)) {
- printf("poped: %ld\t", vt_long.pop_back(&example));
- printf("new size: %ld\n", example.size);
- }
- vt_long.free(&example);
- return 0;
- }
- /*
- * $ gcc ./test.c vector.h
- * $ ./a.out
- * index 0: 1
- * index 1: 2
- * index 2: 3
- * index 3: 4
- * index 4: 5
- * index 5: 6
- * index 6: 7
- * index 7: 8
- * index 8: 9
- * index 9: 10
- * index 10: 11
- * index 11: 12
- * index 12: 13
- * index 13: 14
- * index 14: 15
- * poped: 15 new size: 14
- * poped: 14 new size: 13
- * poped: 13 new size: 12
- * poped: 12 new size: 11
- * poped: 11 new size: 10
- * poped: 10 new size: 9
- * poped: 9 new size: 8
- * poped: 8 new size: 7
- * poped: 7 new size: 6
- * poped: 6 new size: 5
- * poped: 5 new size: 4
- * poped: 4 new size: 3
- * poped: 3 new size: 2
- * poped: 2 new size: 1
- * poped: 1 new size: 0
- */
Add Comment
Please, Sign In to add comment