﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Algs4.Helper.SortHelper;

namespace Algs4.Algorithms
{
    public class MergeBU
    {
        public static void Sort<T>(List<T> list)
        {
            var size = 1;
            for (int i = 0; i < list.Count; i += size)
            {

            }
        }

        public static void Merge<T>(List<T> list, int i, int mid, int j)
        {
            if (i >= j) return;
            var left = i;
            var right = mid;
            var mark = i;
            var temp = new List<T>();
            temp = list.GetRange(i, j - i + 1);
            while (left < mid && right < j)
            {
                if (less(temp[left - i], temp[right - i]))
                {
                    list[mark] = temp[left - i];
                    left++;
                    mark++;
                }
                else
                {
                    list[mark] = temp[right - i];
                    right++;
                    mark++;
                }
            }
            for (int m = left; m < mid; m++)
            {
                list[mark] = temp[m - i];
                mark++;
            }
            for (int n = right; n <= j; n++)
            {
                list[mark] = temp[n - i];
                mark++;
            }
        }
    }
}
