Beispiel #1
0
        public List <TravelCard> GetOrderedCards(List <TravelCard> cards)
        {
            if (cards == null || cards.Count == 0)
            {
                throw new ArgumentException(nameof(cards));
            }

            TravelCard        firstCard    = GetFirstCard(cards);
            List <TravelCard> orderedCards = GetOrderedCardsByMovingFromFirstToLast(firstCard, cards);

            return(orderedCards);
        }
Beispiel #2
0
        private List <TravelCard> GetOrderedCardsByMovingFromFirstToLast(TravelCard firstCard, List <TravelCard> cards)
        {
            var result = new List <TravelCard> {
                firstCard
            };
            Dictionary <string, TravelCard> dictionary = cards.ToDictionary(x => x.DeparturePoint, x => x);
            TravelCard currentCard = firstCard;

            while (dictionary.ContainsKey(currentCard.DestinationPoint))
            {
                var nextCard = dictionary[currentCard.DestinationPoint];
                result.Add(nextCard);
                currentCard = nextCard;
            }

            return(result);
        }
Beispiel #3
0
        private bool HasNoCardBefore(TravelCard travelCard, string[] orderedDestinationPoints)
        {
            int elementIndex = Array.BinarySearch(orderedDestinationPoints, travelCard.DeparturePoint);

            return(elementIndex < 0);
        }