/// <summary> /// The bubble sort. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="items">The items.</param> /// <param name="reflectorUtils">The reflector utils.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="items"/> /// or /// <paramref name="reflectorUtils"/> /// </exception> public void BubbleSort <T>(T[] items, IReflectorUtils reflectorUtils) { if (ReferenceEquals(items, null)) { throw new ArgumentNullException(nameof(items)); } if (ReferenceEquals(reflectorUtils, null)) { throw new ArgumentNullException(nameof(reflectorUtils)); } bool swapped; do { swapped = false; for (int i = 1; i < items.Length; i++) { IComparable indexMinusOneItem = reflectorUtils.GetPropValue(items[i - 1]) as IComparable; object indexItem = reflectorUtils.GetPropValue(items[i]); if (indexMinusOneItem.CompareTo(indexItem) > 0) { Swap(items, i - 1, i); swapped = true; } } }while (swapped != false); }
public HotelService() { IUnitOfWork unitOfWork = new UnitOfWork(); hotelRepository = unitOfWork.HotelRepository; reflectorUtils = new ReflectorUtils(); arrayUtils = new ArrayUtils(); }