Question: Code in C please! Common Notes Assume that all inputs are valid. No error checking is required on inputs. To compile both files lab5.c andlab5main.c,

 Code in C please! Common Notes Assume that all inputs are

Code in C please!

Common Notes

Assume that all inputs are valid. No error checking is required on inputs.

To compile both files lab5.c andlab5main.c, use the following command: cc lab5.c lab5main.c

LAB 5 Pointers to Structures and Dynamic Memory Allocation 1. Specification The extendable array data structure allows the array capacity to be increased or reduced according to the current array utilization. We implement a simple extendable array data structure in which elements are inserted at and removed from only one end of the array (the rear in this exercise). Write a C program to implement the insertion and deletion operations, extending or shrinking the array as needed. 2. Implementation The program to be submitted is named lab5.c. Use the given template lab5.c and fill in your code. Submit only file lab5.c. You are also given a file named lab5main.c to test your code. Do not submit file lab5main.c. The first function to be implemented is insertLast(). See file lab5.c for its specification. The new element is to be inserted at the rear of the extendable array. When a new element is inserted into a full array, extend the array by doubling its current capacity C(e.g., if C == 4 then C is increased to 8). Use function malloc or calloc to allocate memory for an array. Allocate a new array; copy the content of the old (smaller) array to the new (bigger) array; free the old array. The second function to be implemented is removeLast(). See file lab5.c for its specification. The function removes and returns the last element of the array (i.e., the element that was inserted last). If the array is empty, the function calls function printErr() to display an error message and returns -1. After a deletion, if the number of elements in the array falls below C/4 (size

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!