Written: 2022/03/21
Tags: C++, exercises, lecture 3, arrays, pointers, STL containers
Summary
Solutions to the exercises proposed at the end of Lecture 3, held on March 18th, 2022.
Solutions
Solutions
Exercise 1
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
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).