Beispiel #1
0
        private static DataArray Merge(DataArray left, DataArray right)
        {
            DataArray result;

            if (right.GetType() == typeof(MyDataArray))
            {
                result = new MyDataArray(left.Length + right.Length);
            }
            else
            {
                result = new MyFileArray(left.Length + right.Length);
            }
            while (left.Length > 0 || right.Length > 0)
            {
                if (left.Length > 0 && right.Length > 0)
                {
                    if (left.First() <= right.First()) //lyginam pirmus elementus
                    {
                        result.Add(left.First());      //idedam pirma
                        left.RemoveFirst();            //pasalinam is kairio pirma
                    }
                    else
                    {
                        result.Add(right.First());
                        right.RemoveFirst();
                    }
                }
                else if (left.Length > 0)
                {
                    result.Add(left.First());
                    left.RemoveFirst();
                }
                else if (right.Length > 0)
                {
                    result.Add(right.First());

                    right.RemoveFirst();
                }
            }
            return(result);
        }