Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions