Question: C langauge Complete the function that transforms a bag into a set in the following code-- A set cannot have repeated instances of the same

C langauge

Complete the function that transforms a bag into a set in the following code-- A set cannot have repeated instances of the same element. Your function void bag2set(struct DynArr *da) should call the functions that you implemented for the first part of HW2 in

In void bag2set(struct DynArr *da), you should also free the memory space allocated to the input bag, since the bag is not needed any more after exiting the function.

You may use the provided main function for testing your code. Note that you would need to fix the data type in dynArray.h as #define TYPE double

/* bag2set.c */

#include

#include

#include

#include "dynArray.h"

/* Converts the input bag into a set using dynamic arrays

param: da -- pointer to a bag

return value: void

result: after exiting the function da points to a set

*/

void bag2set(struct DynArr *da)

{

/* FIX ME */

}

/* An example how to test your bag2set() */

int main(int argc, char* argv[]){

int i;

struct DynArr da; /* bag */

initDynArr(&da, 100);

da.size = 10;

da.data[0] = 1.3;

for (i=1;i

da.data[i] = 1.2;

}

printf("Bag: ");

for (i=0;i

printf("%g ", da.data[i]);

}

printf(" ");

printf("Set: ");

bag2set(&da);

for (i=0;i

printf("%g ", da.data[i]);

}

printf(" ");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!