For the given scenario, I would prefer to use Arrays over the Linked Lists.
Efficient Filtering: Arrays store elements in contiguous memory locations, which allows fast
iteration when we will be filtering products based on attributes. For carts with a number of items,
arrays (or dynamic arrays like Vectors in C++) offer straightforward implementation and
management.
As we know that elements in Linked Lists are in different positions, so we will need to maintain
the address of each node in Linked List through pointers and it also uses more memory.
Accessing elements requires sequential traversal from the head making filtration difficult.
Adding and removing: Adding or removing items at the start or end of the Linked List is also
simple. But for filters and cart management as mentioned in our case Link List is not really
needed because we can use the vector array which can grow and shrink dynamically and it also
manages the shift operation itself so we also don’t really need to shift the items manually in case
of deleting an element from some specific index or even in the middle it would not be an issue If
we use Vector Array.
An Array (or a dynamic array structure) is more suitable for this scenario due to its efficient
iteration, random access capabilities, and simplicity in managing the items.