Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 21 [9 marks] In two labs, you developed a C module that implements a list collection. It used a dynamically struct and a dynamically

image text in transcribed
Question 21 [9 marks] In two labs, you developed a C module that implements a list collection. It used a dynamically struct and a dynamically allocated array as the underlying data structure. list's "type: allocated Here is the declaration of the typedef struct f int elems; // Points to the backing array of ints. int capacity; // Maximum number of elements in the list. size; Current number of elements in the 1ist. int intlist t; Write a function named intlist_slice that returns a pointer to a new list that is initialized with a slice" of values copied from the list pointed to by src: intlist_t *intlist_slice(intlist_t *src, int i, int j); The values copied from the source list are the sequence of integers with index k, such that k j. In other words, the function initializes the new list with values copied from the source list, starting with index i and ending with index j-1 The capacity of the new list must be twice its size. The list pointed to by src is not modified by this function. For example, suppose parameter sre points to a list containing 13,2,5,7,8,2,9,6), parameter i is 2 eter j is 6. The function will return a new list with capacity 8 containing (5,7,8,21. The list and parame pointed to by src will still contain [3, 2, 5,7,8,2,9,6 The function must terminate (via assert) if it is passed a NULL pointer or if i or j are not valid indices. Your intlist_slice function is only permitted to call functions from the C standard library (see the the list modulc crib sheet at the end of this question paper). It is not permitted to call any functions from you developed in the labs; e.g. intlist construct, intlist_append, etc

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

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions