Selecting an Implementation
We have studied arrays, vectors, and linked lists. Say which you would use to implement each situation below. Defend every answer by saying why the answer you chose is better than the other two possibilities.
1. We have unknown number of participants at a public hearing.
As each person arrives, name is entered into the system.
In this case, vector is the best to use as it can grow in size,
when needed.
Vector
2. Temperature is recorded for every 5 mins for 24 hrs. That means, we need to record total 288 times in a day. Since we have a fixed number, we can use an array. It provides advantages of being able to access any element immediately and it is best for performing Sorting.
Array
3. At the subway shop, people come and go. We need to be able to keep track of arrivals and departures. In this case, it's best to use a linked list, as Linked list can dynamically grow in size. Arrivals happen at one end and departures at another end. This case can easily be handled by a Linked List in constant time.
Linked List
Get Answers For Free
Most questions answered within 1 hours.