5 int* create_tab(int tab
[], unsigned tab_size
) {
6 tab
= malloc(sizeof(int) * tab_size
);
10 /* initialize to zero the integer array */
11 for (unsigned i
= 0; i
< tab_size
; i
++) {
18 void free_tab(int tab
[]) {
22 /* we suppose both tabs are already created */
23 static void copy_tab(int src_tab
[], int dest_tab
[], unsigned src_tab_size
, unsigned index_offset
) {
24 /* FIXME: I think it's worth doing some sanity checks on the array size:
25 * dest_tab_size >= src_tab_size */
26 for (unsigned i
= 0; i
< src_tab_size
; i
++) {
27 dest_tab
[i
+ index_offset
] = src_tab
[i
];
31 int* concat_tab(int tab1
[], unsigned tab_size1
, int tab2
[], unsigned tab_size2
, int tab_dest
[]) {
32 int* rt
= create_tab(tab_dest
, tab_size1
+ tab_size2
);
34 copy_tab(tab1
, tab_dest
, tab_size1
, 0);
35 copy_tab(tab2
, tab_dest
, tab_size2
, tab_size1
);
39 int* resize_tab(int tab
[], unsigned new_tab_size
) {
40 tab
= realloc(tab
, sizeof(int) * new_tab_size
);
48 /* number of occurences of an element in an unsorted array */
49 int count_tab_element(int tab
[], unsigned tab_size
, int element
) {
50 unsigned el_count
= 0;
51 for (unsigned i
= 0; i
< tab_size
; i
++) {
52 if (tab
[i
] == element
) {
59 void sort_tab(int tab
[], unsigned tab_size
, criteria_cb criteria
) {
60 sort_bubble_array(tab
, tab_size
, criteria
);