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

C Programming only. c:users\'ijareDocumentsCSE 31yLab3tvector.c-Notepad+- File E

ID: 3910779 • Letter: C

Question

C Programming only.

c:users'ijareDocumentsCSE 31yLab3tvector.c-Notepad+- File Edit Search View Enceding Language Settings Toos Macro Run Plugins indow? include A Includa our header fincludes 6 »,rector, . h“ ? /1 Define what our struct Le? eize t aize; int data: 12 15 t *'vector vector_t retal: EV?ct,or new() FirSt, o nood to allocate tho iemory tor tho atruct retval= ?ve ::tort*)mai înc( * sizeof (vectort)); - - if (reLalNULL 23 24 returD NULL Why oes the above atatement cast the malloe's return value to 'veatort 29 7x Now nced to initialize our dat? */ tree (retval) Iecur 40 42 and return... * return retval 45 16 4 8 source file length:z inas Windows tCL 4:57 PM Type here to search 2218

Explanation / Answer

There are two methods need to be written:

void vetcor_delete(vector_t *v){

    if (v != NULL){

        if (v->data != NULL){
           free(v->data);
        }
        free(v);
    }
}

void vector_set(vector_t *v, size_t loc, int value){

    if (v != NULL){

        if (loc >= v->size || loc < 0){
            printf(" Invalid location ");
        }
        else {
          
               v->data[loc] = value;
           
           
        }
    }
    else {
        printf("Vector is null ");
    }


}