ListForeachPtrInRange

Table of Contents

ListForeachPtrInRange

Description

This macro performs forward traversal, starting at index start (inclusive) and continuing until index end (exclusive), assuming zero-based indexing. Since linked lists are not indexable, the traversal walks node-by-node and skips nodes before start, then continues while tracking the current index.

Parameters

NameDirectionDescription
lin,outList to iterate over.
varin,outName of the pointer variable to be used which will point to the current element during iteration.
startinStarting index (inclusive).
endinEnding index (exclusive).

Usage example (Cross-references)

    if (start < end) {
    int sum = 0;
    ListForeachPtrInRange(list, item_ptr, start, end) {
    sum += *item_ptr;
    }

Share :

Related Posts

ListForeach

ListForeach Description Iterate over each element var of the given list l. The variable var is declared and defined by this macro. Iteration happens in forward order, starting from the head of the list and continuing through the next pointers until the end is reached. The variable var will contain a copy of the value pointed to by each list node.

Read More

ListForeachReverse

ListForeachReverse Description Iterate over each element var of the given list l in reverse order. The variable var is declared and defined by this macro. Iteration happens in reverse, starting from the tail of the list and continuing through the prev pointers until the head is reached. The variable var will contain a copy of the value pointed to by each list node.

Read More

ListForeachInRange

ListForeachInRange Description Iterate over each element var of the given list l in the index range [start, end). The variable var is declared and defined by this macro. This macro performs forward traversal, starting at index start (inclusive) and continuing until index end (exclusive), assuming zero-based indexing. Since linked lists are not indexable, the traversal walks node-by-node and skips nodes before start, then continues while tracking the current index.

Read More