Exemplo n.º 1
0
        public List <ContainerValuable> getContainersValuableSorted(List <IContainer> containers)
        {
            List <IContainer>        clonedList = new List <IContainer>(containers);
            List <ContainerValuable> sortedList = new List <ContainerValuable>();

            foreach (ContainerValuable container in containers.OfType <ContainerValuable>())
            {
                ContainerValuable maxContainerValuable = getMaxWeightContainerValuable(clonedList);
                sortedList.Add(maxContainerValuable);
                clonedList.Remove(maxContainerValuable);
            }
            return(sortedList);
        }
Exemplo n.º 2
0
        public ContainerValuable getMaxWeightContainerValuable(List <IContainer> containers)
        {
            int maxWeight = 0;
            ContainerValuable maxWeightContainer = null;

            foreach (ContainerValuable container in containers.OfType <ContainerValuable>())
            {
                if (container.weight > maxWeight)
                {
                    maxWeightContainer = container;
                    maxWeight          = container.weight;
                }
            }
            return(maxWeightContainer);
        }