```
virtual Indexed<T>& sort(Indexed<T>& data)
{
    //base case

    Vector<T> temp1, temp2, temp3;
    //for (int i = 0; i < data.getSize(); i++)
    //{
    //  cout << data.getElementAt(i) << ", ";
    //}
    mergeSortHelper(data, 0, data.getSize() - 1, temp1, temp2);
    for (int i = 0; i < data.getSize(); i++)
    {
        cout << data.getElementAt(i) << ", ";
    }
    cout << endl;
    return data;
}

void mergeSortHelper(Indexed<T>& data, int begin, int end, Vector<T> &left, Vector<T> &right)
{
    //base case, if there is only 1 item in each side, merge them and return
    if ((begin - end) == 0)
    {
        //left.setElementAt(data.getElementAt(begin), 0);
        //left = storage;
        return;

    }
    else
    {
        //Vector<T> right;
        int midPoint = (end + begin) / 2;
        mergeSortHelper(data, begin, midPoint, left, right);
        mergeSortHelper(data, midPoint + 1, end, left, right);
        //perform merging

        int i = 0, leftCounter = 0, leftLimit = (midPoint - begin) + 1, rightCounter = 0, rightLimit = (end - (midPoint + 1)) + 1;
        for (int i = 0; i < leftLimit; i++)
        {
            if (i < leftLimit)
                left.setElementAt(data.getElementAt(begin + i), i);
            if (i < rightLimit)
                right.setElementAt(data.getElementAt(midPoint + 1 + i), i);
            //cout << left.getElementAt(i) << ", ";
        }
        while (leftCounter < leftLimit || rightCounter < rightLimit)
        {
            if (leftCounter >= leftLimit)
            {
                //done sorting the left side
                data.setElementAt(right.getElementAt(rightCounter), begin + i);
                //temp.setElementAt(right.getElementAt(rightCounter), i);
                rightCounter++;
            }
            else if (rightCounter >= rightLimit)
            {
                //done sorting the right side
                data.setElementAt(left.getElementAt(leftCounter), begin + i);
                //temp.setElementAt(left.getElementAt(leftCounter), i);
                leftCounter++;
            }
            else
            {
                if (left.getElementAt(leftCounter) < right.getElementAt(rightCounter))
                {
                    data.setElementAt(left.getElementAt(leftCounter), begin + i);
                    //temp.setElementAt(left.getElementAt(leftCounter), i);
                    leftCounter++;
                }
                else if (left.getElementAt(leftCounter) > right.getElementAt(rightCounter))
                {
                    data.setElementAt(right.getElementAt(rightCounter), begin + i);
                    //temp.setElementAt(right.getElementAt(rightCounter), i);
                    rightCounter++;
                }
                else
                {
                    data.setElementAt(right.getElementAt(rightCounter), begin + i);
                    //temp.setElementAt(right.getElementAt(rightCounter), i);
                    i++;
                    data.setElementAt(left.getElementAt(leftCounter), begin + i);
                    //temp.setElementAt(left.getElementAt(leftCounter), i);
                    leftCounter++;
                    rightCounter++;

                }

            }
            i++;
        }

    }

    //return temp;

```

Where else can I improve to make the sort faster? I've been speding so much time on this just make it to work properly. But as I recall from class quick sort and merge sort are O(NlogN) but my quickSort code above is not that efficient, it takes 2.5 times longer to sort the same number of item.