Your implementation of
Sortwould be optimised by implementingIndexOfMinso thatMin = Item(IndexOfMin)(with a caveat for an emptyList), but you can then use the O(1)RemoveAtinstead of the O(n)Removeat the end of theDo Untilloop. Similarly forIndexOfMax,MaxandSortDescending, of course. I'd consider makingIndexOfMinandIndexOfMaxPublicto allow other code to use the same optimisation.IMHO, especially from a VB6 POV and contrary to Mat's Mug, sorting an empty
Listshould succeed and return the emptyList, not throw an error. I.e.IsSortableshould start:IsSortable = True If Count = 0 Then Exit Function
Your existing Sort and SortDescending implementations don't need to change for this.
- (EDIT: Added 6 months later :-) ) Your implementation of
LastIndexOfshould actually be the same asIndexOf, but withFor i = Count To 1 Step -1.
Minor quibbles
This is more readable (from a VB6 POV, anyway), and, of course, minusculely faster:
Public Sub RemoveRange(ByVal Index As Long, ByVal valuesCount As Long) 'Removes a range of elements from the List. Dim i As Long For i = 1 To valuesCount RemoveAt Index Next End Subvalueis unused inAddValues.Clearshould useRemoveAt 1. (I've forgotten my VB6 optimisations:I knowRemoveAt 1is the standard idiom, but isRemoveAt Countfaster? NO: I've checked it andRemoveAt 1is 9 orders of magnitude faster!)