Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool test_list_iter()
- {
- bool failed = false;
- // List: 4 -> 9 -> 5 -> NULL;
- List *lt = list_init(3, 4, 9, 5);
- if (lt == NULL) {
- perror("Failed to allocate List lt");
- return false;
- }
- int arr[] = {4, 9, 5};
- size_t i = 0;
- // Iterate through lt.
- for (Node *it = list_start(lt); !list_end(it); it = list_next(it)) {
- if (node_value(it) != arr[i]) {
- failed = true;
- goto LIST_FREE;
- }
- i++;
- }
- LIST_FREE:
- list_free(lt);
- if (failed) {
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement