My linked list is about a video store .
I should make a list with video details ( I know this part) and a list of customer details.
Now the CUSTOMER list (The second nodetype) is where my problem lies.
I have to display the customer’s name ,acc no. etc AND the videos checked in and out by that customer (deleting and inserting videos to the customer list)
So my doubt is ,how do i do this deletion and insertion of JUST videos under a single person s name..
EG: Customer list has lots of different customers with different names and acc numbers and rented videos.
One customer john rents 2 or 4 different videos and rented out some videos too.
now HOW do I show that ONLY John rented these videos (that is i ve to insert videos under his name only and not any other customer)
I hope now people got me…I want to know how this can be done?
If I understand correctly, this is a design question, and has nothing to do with linked lists in C++.
For the rest of the implementation, I assume the following:
Nvideos.Krentals, where0 <= K <= N.Mcustomers. There is no relationship betweenNandM, but it would be safe to assume that there may be many more customers than videos and that most of the time, most of the videos are not rented (Mmuch larger thanN, which is much larger thanK).std::stringorstd::list.You have the following struct/classes.
struct Customer {
int account_number;
char * name;
// … other customer info …
};
struct Video {
char * title;
// … other video info …
};
Solution 1: per-customer list of rentals
Add a “list of rentals” your
Customerclass. This is convenient for listing rentals by customer, but is problematic when you need to validate that a video is not already rented. The first is constant-time, but the second is linear inM+K(loop over all customers, then each customer’s rentals).Solution 2: per-video pointer to customer
Add a “point to customer” in your
Videoclass. Checking if a video is not already rented is constant time (check ifvideo->customeris set to some non-default value —NULLin C,nullin Java,Nonein Python, etc.), but listing movies rented by a specific customer is linear inN.Solution 3: list of rentals
Add a 3rd list to track rentals separately. Define a
Rentalclass that has a pointer toCustomerand a pointer toVideo. Then, define a list of rentals. Listing all rentals by a customer and checking if a video is already rented are both linear inK.This solution gives you the best algorithmic complexity and also happens to mimic more closely what you’d do with an SQL database in a real commercial application for tracking a video store’s customers, videos and rentals.