ListForeachReverseInRange

Table of Contents

ListForeachReverseInRange

Description

Iterate over each element var of the given list l in reverse, limited to index range [start, end) relative to the tail of the list. Index 0 corresponds to the tail, 1 to the previous node, and so on. The variable var is declared and defined by this macro. Since linked lists do not support indexing, this macro counts nodes from the tail and includes only those where the relative reverse index lies in [start, end).

Parameters

NameDirectionDescription
linList to iterate over.
varin,outName of the variable to be used which will contain the value of the current element during iteration.
startinStarting index from tail (inclusive).
endinEnding index from tail (exclusive).

Usage example (Cross-references)

    if (start < end) {
    int sum = 0;
    ListForeachReverseInRange(list, item, start, end) {
    sum += item;
    }

Share :

Related Posts

VecForeachInRange

VecForeachInRange Description Iterate over elements in a specific range of the given vector v. This is a convenience macro that iterates over a range using an internally managed index. The variable var is declared and defined by this macro.

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

ListForeachPtr

ListForeachPtr Description Iterate over each element var (as a pointer) of the given list l. The variable var is declared and defined by this macro as a pointer to the list’s data type. 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 point to the data associated with each list node.

Read More