Written: 2023/03/26

Tags: C++, exercises, lecture 3, arrays, pointers, STL containers

Summary

Solutions to the exercises proposed at the end of Lecture 3, held on March 21st, 2023.

Solutions

Exercise 1

Write a program that, given two arrays of equal size, uses a function that merges them into a single array having elements from the first and the second one alternating every position (e.g. input: [1,2,3], [7,8,9], output: [1,7,2,8,3,9];Β  hint: function should accept three array parameters, the last one being double the size of the first two).

Exercise 2

Implement the same program of Exercise 1 using STL containers (not necessarily of the same size) and iterators (hint: use vector and pass-by-reference mechanism).