|
A shopping cart is essentially a collection of items that a customer intends to purchase. We need a data structure that can efficiently:
Add items to the cart
Remove items from the cart
Calculate the total price of the items
Retrieve the list of items in the cart
Given these requirements, several data structures can be considered:
Array:
Pros: Simple implementation, efficient random access.
Cons: Fixed size, inefficient Phone Number insertions and deletions in the middle.
Pros: Dynamic size, efficient insertions and deletions in the middle.
Cons: Inefficient random access.
Pros: LIFO order, simple implementation.
Cons: Limited operations (push, pop).
|
|