Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part I Write a program in C. Please implement the addDynArr, getDynArr, putDynAr

ID: 3783758 • Letter: P

Question

Part I

Write a program in C. Please implement the addDynArr, getDynArr, putDynArr and swapDynArr functions in dynamicArray.c

Part II

Currently, the array will never shrink.

Your task is to modify the given functions (do not modify the prototypes) to shrink the array to half its capacity when a remove causes the size to be 1/3rd of the capacity. Please modify dynamicArray.c so that it correctly resizes the array as described above. When you make a change to a function please put a comment like so

// PART II:

*/

/* Put an item into the dynamic array at the specified location, overwriting the element that was there param: v pointer to the dynamic array param: pos the index to put the value into param: val the value to insert pre: v is not null pre: v is not empty pre: pos >= 0 and pos < size of the array post: index pos contains new value, val

*/

Explanation / Answer

#ifndef DYNAMIC_ARRAY_INCLUDED

#define DYNAMIC_ARRAY_INCLUDED 1

# ifndef TYPE

# define TYPE      int

# define TYPE_SIZE sizeof(int)

# endif

# ifndef LT

# define LT(A, B) ((A) < (B))

# endif

# ifndef EQ

# define EQ(A, B) ((A) == (B))

# endif

typedef struct DynArr DynArr;

/* Dynamic Array Functions */

DynArr *createDynArr(int cap);

void deleteDynArr(DynArr *v);

DynArr* newDynArr(int cap);

int sizeDynArr(DynArr *v);

void addDynArr(DynArr *v, TYPE val);

TYPE getDynArr(DynArr *v, int pos);

void putDynArr(DynArr *v, int pos, TYPE val);

void swapDynArr(DynArr *v, int i, int j);

void removeAtDynArr(DynArr *v, int idx);

/* Stack interface. */

int isEmptyDynArr(DynArr *v);

void pushDynArr(DynArr *v, TYPE val);

TYPE topDynArr(DynArr *v);

void popDynArr(DynArr *v);

/* Bag Interface */

int containsDynArr(DynArr *v, TYPE val);

void removeDynArr(DynArr *v, TYPE val);

#endif

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote