These definitions and functions give a specific implementation of a data abstraction: collection with operations set, insert, omit, and belongs allowed. This is the only portion of the program that needs to be changed when the implementation of the data abstraction is changed. MAXN sets a limit on the size of arrays of type collection, so it sets a limit for n.

#define TRUE 1

#define FALSE 0

#define MAXN 500

typedef int collection[MAXN];

set(n,c)

/* Sets c to empty */

int n;

collection c;

{

int i;

for (i=1;i<=n;i++)

c[i] = FALSE;

}

insert(i,c)

/* Inserts i in c */

int i;

collection c;

{

c[i] = TRUE;

}

omit(i,c)

/* Removes i from c */

int i;

collection c;

{

c[i] = FALSE;

}

belongs(i,c)

/* Returns true only

if i is in c

*/

int i;

collection c;

{

return(c[i]);

}