I have a number of linked lists, currently 5, each modelling a checkout line. But in the future i may choose to ad more
I want to compare each linked list and return the linked list with the smallest size
What is the best/easiest way to do this?
Could i make a list of linked lists, or an array of linked lists and iterate through these comparing the sizes?
You could either define a class, say, CheckoutGroup or something like that, that includes all the checkout lanes, plus whatever other administrative stuff makes sense.
Or, if you're not doing anything with them as a group other than finding out which one has the shortest line, just define a method that takes List of Lists and finds the shortest one.
And yes, you can make an array of Lists, List of Lists, List of arrays, array of arrays of List of arrays of Lists, and so on. Lists and arrays are objects, and they can be stored in a List or array just like any other object. I would lean toward a List rather than an array, since it will auto-resize itself as needed.
And of course, rather than asking "Can I do this?" since you already have some idea about Lists and arrays and an idea of how to use them, you could have first tried it before posting.
Joined: Apr 27, 2012
I wanted to see if there was a preferred way to do it.
I was thinking something along the lines of this, although i was hoping .get(i).size() would retrieve the size of the LinkedList, instead it looks for a method size(). Is there a way to retrieve the linkedList size the way i have started above
2) You're not adding your individual lists to the main list. Instead, you're adding each of their items.
You want a list of checkout lanes, and you want to look at the size of each element in that list--that is, the number of people in the checkout lanes. So you need to add the checkout lanes to that list. But you're not doing that. You're adding the people in the individual lanes into that bigger list, with no regard for the "This lane contains these people" structure. If you had used generics, this would not have been possible, as the compiler would let you add a Person to a list that's supposed to contain List of Person.
Joined: Apr 27, 2012
I have worked it out now thanks, it now adds a customer to the queue with the least customers.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com