Exemplo n.º 1
0
        static PlacementResult Sort(MyType[] array, MyType typeA, MyType typeB, int left, int right)
        {
            int placeLeft = left;
            int placeRight = right;

            while (array[placeLeft] == typeA)
            {
                placeLeft++;
            }

            while (array[placeRight] == typeB)
            {
                placeRight--;
            }

            for (int i = placeLeft; i <= placeRight;)
            {
                if (array[i] == typeA)
                {
                    array.Swap(i, placeLeft++);
                }
                else if (array[i] == typeB)
                {
                    array.Swap(i, placeRight--);
                }
                else
                {
                    i++;
                }
            }

            return new PlacementResult() { LeftPlace = placeLeft, RightPlace = placeRight };
        }