ListReverse
Description
Reverse the order of nodes in the list in place.
Parameters
| Name | Direction | Description |
|---|---|---|
l |
in,out | List to be reversed. |
Success
Returns to the caller. The previous head is now the tail and vice versa; every next / prev link has been flipped. The list length is unchanged.
Failure
Function cannot fail.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
ListInt.c:130:
// Advanced operations
case LIST_INT_REVERSE : {
ListReverse(list);
break;
}- In
List.Ops.c:74:
static bool test_list_sort_and_reverse(void) {
WriteFmt("Testing ListSort and ListReverse\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
List.Ops.c:90:
bool result = list_matches(GENERIC_LIST(&list), (const int[]) {1, 2, 2, 3, 4}, 5);
ListReverse(&list);
result = result && list_matches(GENERIC_LIST(&list), (const int[]) {4, 3, 2, 2, 1}, 5);- In
List.Ops.c:99:
static bool test_list_sort_and_reverse_edge_cases(void) {
WriteFmt("Testing ListSort and ListReverse edge cases\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
List.Ops.c:108:
ListSort(&empty, compare_ints);
ListReverse(&empty);
ListPushBackR(&singleton, 42);
ListSort(&singleton, compare_ints);- In
List.Ops.c:111:
ListPushBackR(&singleton, 42);
ListSort(&singleton, compare_ints);
ListReverse(&singleton);
bool result = (ListLen(&empty) == 0) && (ListHead(&empty) == NULL) && (ListTail(&empty) == NULL);
Last updated on