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
Ops.c:112:
static bool test_list_sort_and_reverse(void) {
WriteFmt("Testing ListSort and ListReverse\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Ops.c:128:
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
Ops.c:137:
static bool test_list_sort_and_reverse_edge_cases(void) {
WriteFmt("Testing ListSort and ListReverse edge cases\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Ops.c:146:
ListSort(&empty, compare_ints);
ListReverse(&empty);
ListPushBackR(&singleton, 42);
ListSort(&singleton, compare_ints);- In
Ops.c:149:
ListPushBackR(&singleton, 42);
ListSort(&singleton, compare_ints);
ListReverse(&singleton);
bool result = (ListLen(&empty) == 0) && (ListHead(&empty) == NULL) && (ListTail(&empty) == NULL);
Last updated on