Question: I need help creating the first three functions from my header file cda.h IN C# I need help with *newcda, setCDADisplay and setCDAfree, below is
I need help creating the first three functions from my header file cda.h IN C#

I need help with *newcda, setCDADisplay and setCDAfree, below is the rest of my cda.c file
#include
#include
#include
#include "cda.h"
struct cda{
int first, last, size, capacity;
int items, index;
void **array;
void (*display)(void *, FILE *);
void (*free)(void *);
};
void sizeFix(CDA *items, int cap,int j)
{
void **temp = malloc(sizeof(void *) * cap);
for(int i = j; i size + j; ++i)
temp[i] = getCDA(items,i-j);
items->capacity = cap;
items->array = temp;
items->first = 0;
items->last = items->size - 1;
}
// Insert CDA
void insertCDA(CDA*items, int index, void *value)
{
assert(value != 0);
if(items->size ==0)
{
items->array[0] = value;
items->first = 0;
items->last = 0;
index++;
}
// Insert CDA FRONT
else if (items->size
{
insertCDAfront(items,value);
if (items->size + 1 > items->capacity)
{
//displayCDA(stdout,items);
int cap = items->capacity * 2;
void **temp = malloc(sizeof(void *) * cap);
for(int i = 0; i size; ++i)
temp[i+1] = getCDA(items,i);
items->array = temp;
items->capacity = cap;
items->last = items->size;
items->first = 0;
}
else if (items->first - 1
items->first = items->capacity - 1;
else
--items->first;
items->array[items->first] = value;
}
// Insert CDA BACK
else if(items->size > 0)
{
//items->array[items->last] = value;
if (items->size + 1 > items->capacity)
{
insertCDAback(items, value);
int cap = items->capacity * 2;
void **temp = malloc(sizeof(void *) * cap);
for(int i = 0; i size; ++i)
temp[i] = getCDA(items,i);
items->array = temp;
items->capacity = cap;
items->last = items->size;
items->first = 0;
}
else ++items->last;
items->array[items->last] = value;
}
else {
return;
}
++items->size;
}
//Remove CDA
void *removeCDA(CDA *items,int index)
//void *removeCDA(CDA *items,0)
{
// Remove CDA Front
if (items->first)
{
assert(items->size >=1);
//displayCDA(stdout,items);
--items->size;
void *val = items->array[items->first];
items->first = (items->first + 1) % items->capacity;
if (items->capacity > 1 && (double)items->size / items->capacity
{
int cap = items->capacity / 2;
sizeFix(items,cap,0);
}
index--;
//printf(" items size now %d ",items->size);
return val;
}
// Remove CDA BACK
else{
assert(items->size >=1);
--items->size;
void *val = items->array[items->last];
items->last = (items->last -1 + items->capacity) % items->capacity;
if(items->capacity > 1 && (double) items->size / items->capacity
{
int cap = items->capacity / 2;
sizeFix(items,cap,0);
}
return val;
}
}
void unionCDA(CDA *recipient,CDA *donor)
{
if(recipient->size == 0)
{
recipient->array = realloc(recipient->array,sizeof(void *) * donor->capacity);
recipient->capacity = donor->capacity;
recipient->first = donor->first;
recipient->last = donor->last;
}
for (int i = 0; i size; ++i)
insertCDAback(recipient,getCDA(donor,i));
free(donor->array);
donor->array = malloc(sizeof(void *));
donor->array[0] = 0;
donor->size = 0;
donor->first = 0;
donor->last = 0;
}
void *getCDA(CDA *items,int index)
{
assert(index >= 0);
assert(index size);
//printf("in hither");
if (items->first > items->last)
{
//printf("this condition");
if (items->first + index capacity)
return items->array[items->first + index];
else
return items->array[index+items->first-items->capacity];
}
else
{
//printf("okay we go here");
return items->array[items->first + index];
}
}
void *setCDA(CDA *items, int index, void *value)
{
if(index == items->size) insertCDAback(items,value);
else items->array[index] = value;
return items->array[index];
}
int sizeCDA(CDA *items)
{
return items->size;
}
void displayCDA(CDA *items, FILE * fp)
{
//printf("first %d, last %d, capacity %d, size %d ",items->first,items->last,items->capacity,items->size);
//printf("items->size = %d ",items->size);
fprintf(fp,"(");
for(int i = 0; i size; ++i)
{
items->display(fp,getCDA(items,i));
if (i+1 size)
fprintf(fp,",");
}
fprintf(fp,")");
}
#ifndef-CDA-INCLUDED- #define-CDA-INCLUDED- #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
