cn_map / cn_map_prev

Syntax

void cn_map_prev(CN_MAP map, CNM_ITERATOR * iterator)

Description

If iterator is pointing to a node in map, proceed to the previous node. If it was pointing at the first node in map, it will point to the return value of cn_map_rend.

Since a CN_Map is sorted internally, iterator will point to the previous node in the sorted sequence of keys in map.

Return Value

N/A

Examples

Basic Usage

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cn_cmp.h"
#include "cn_map.h"

main() {
	CN_MAP map = cn_map_init(char, int, cn_cmp_char);

	char key;
	int  value;

	//Put in a-z with 0-25 in as key/value pairs.
	for (key = 'a', value = 0; key <= 'z'; key++, value++) {
		cn_map_insert(map, &key, &value);
	}

	//Iterate through
	CNM_ITERATOR it;

	for (cn_map_rbegin(map, &it); !cn_map_at_rend(map, &it); cn_map_prev(map, &it)) {
		printf(
			"%c -> %d\n",
			cn_map_iterator_key  (&it, char),
			cn_map_iterator_value(&it, int)
		);
	}
}