I’m writing a project for a basic OOP C++ course. I have to implement sets of objects of a type Media (and derivates Book, Movie, Album). The operations on those sets are: adding an element, removing a certain element (not necessarily the first or last), search through the set (the search could return multiple results). Sorting is not required but I thought it would be a good addition.
So I was wondering, which would be the best data structure? Simple array, vector or list? (Please notice that I must write the implementation, I can’t use std classes.)
I’m not actually concerned for efficiency or memory consumption since I’m not dealing with large sets of data, but I should still be able to explain why I chose one particular data structure.
I thought that a List would be preferable for removing and adding items, but the vector has the indexing operator [] that could be useful for the search function (which could return an array of indexes).
As a home work, I suggest to use a simple linked list at first. For searching, you can return an pointer or iterator(if your List class is compatible with STL container) of the item you have found. And in your case, you have multiple sub-classes, you may need to put the the pointer of the base class – Media in the container. If yes, you need to consider how to manage the memory. e.g. Free the memory when an element is removed.