Generic Functions, Generic Data Structures
Generic Functions, Generic Data Structures
Generic Functions, Generic Data Structures
http://www.isical.ac.in/~dfslab/2018/index.html
#include <stdlib.h>
Sorting
void qsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
Searching
void *bsearch(const void *key, const void *base,
size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
#include <string.h>
1 #ifndef _GSTACK_
2 #define _GSTACK_
3
4 typedef struct {
5 void *elements;
6 size_t element_size, num_elements, max_elements;
7 } STACK;
8
9 STACK newStack(int element_size);
10 // OR
11 void initStack (STACK *s, int element_size);
12 void freeStack(STACK *s);
13 bool isEmpty(const STACK *s);
14 void push(STACK *s, const void *eptr);
15 void pop(STACK *s, void *eptr);
16
17 #endif // _GSTACK_