/* Function |insert| inserts block of ints |toInsert|, having |dim2| elements, i
ID: 3553957 • Letter: #
Question
/* Function |insert| inserts block of ints |toInsert|, having |dim2| elements, into the
/* Function |insert| inserts block of ints |toInsert|, having |dim2| elements, into the
// middle of block of ints |blk|, which has |dim1| elements. The inserted block starts at
// offset |offset|. Data in |blk| are moved down to make room; no data is lost.
// |insert| makes a larger block to accommodate the inserted data, and returns a pointer
// to this larger block, which the caller is expected to use instead of |blk|.
*/
Simplify the code do not add extra just reduce it simpler
int *insert(int *blk, int *toInsert, int dim1, int dim2, int offset) {
int *tmp = calloc(dim1+dim2, sizeof(int));
int *tmp2 = tmp;
int i = offset;
while(offset--) {
*tmp2++ = *blk++;
}
while(dim2--) {
*tmp2++ = *toInsert++;
}
memmove(tmp2, blk, i*4);
return tmp;
}
Explanation / Answer
( Short, Simple, Done in C and EXACTLY following the mentioned Specifications )
( 1 )
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.