Enumerated Type Of Elements Code, programming homework help


A set can be implemented using an enumerated type of elements and an int with bits set to indicate whether an element is present. For example:

//Start of code

typedef enum {SOCCER=1, FOOTBALL=2, RUGBY=4, CRICKET=8} players;

struct set_int


int elements;


typedef struct set_int *set;

//End of code

Implement the following functions for a set:

1) void init_set(set *sp) — create an empty set;

2) void add_element(set s, int e) — update s so that it contains only the element e; and

3) void invert(set s) — update s so that it contains all the elements not in it when the function is called and doesn’t contain the elements which were in it when the function is called.

Include comments explaining your logic.

"Order a similar paper and get 100% plagiarism free, professional written paper now!"

Order Now