ListForeachPtrReverse

Table of Contents

ListForeachPtrReverse

Description

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

Parameters

NameDirectionDescription
lin,outList to iterate over.
varoutName of the pointer variable to be used which will point to the current element during iteration. The type of var will be a pointer to the data type of the list elements (i.e., LIST_DATA_TYPE(l) *).

Usage example (Cross-references)

    if (list->length > 0) {
    int sum = 0;
    ListForeachPtrReverse(list, item_ptr) {
    sum += *item_ptr;
    }

Share :

Related Posts

VecForeachPtr

VecForeachPtr Description Iterate over each element var of the given vector v (as a pointer). This is a convenience macro that iterates forward using an internally managed index and provides a pointer to each element. The variable var is declared and defined by this macro as a pointer to the vector’s data type.

Read More

VecForeachPtrReverse

VecForeachPtrReverse Description Iterate over each element var (as a pointer) of the given vector v in reverse order. This is a convenience macro that iterates backward using an internally managed index and provides a pointer to each element. The variable var is declared and defined by this macro as a pointer to the vector’s data type.

Read More

VecForeachPtrReverseIdx

VecForeachPtrReverseIdx Description Iterate over each element var of given vector v at each index idx into the vector. The variables var and idx declared and defined by this macro. idx will start from v->length - 1 and will go till 0

Read More