Basic Merge Sort C++|| No In-Built Function Used
Complexity\n- Time complexity:\nO(NLOGN)\n\n- Space complexity:\nO(NLOGN)\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> mergesorted(vector<int>&arr)\n
# Complexity\n- Time complexity:\nO(NLOGN)\n\n- Space complexity:\nO(NLOGN)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> mergesorted(vector<int>&arr)\n    {\n        if(arr.size()==1)\n        {\n            return arr;\n        }\n        int dividesize=arr.size()/2;\n        vector<int>merge1,merge2;\n        for(int i=0;i<dividesize;i++)\n        {\n            merge1.push_back(arr[i]);\n        }\n        for(int i=dividesize;i<arr.size();i++)\n        {\n            merge2.push_back(arr[i]);\n        }\n        merge1=mergesorted(merge1);\n        merge2=mergesorted(merge2);\n        int ptr1=0,ptr2=0,ptr3=0;\n        while(ptr3<arr.size())\n        {\n            if(ptr1==merge1.size())\n            {\n                arr[ptr3]=merge2[ptr2];\n                ptr2++;\n                ptr3++;\n                continue;\n            }\n            if(ptr2==merge2.size())\n            {\n                arr[ptr3]=merge1[ptr1];\n                ptr1++;\n                ptr3++;\n                continue;   \n            }\n            if(merge1[ptr1]<merge2[ptr2])\n            {\n                arr[ptr3]=merge1[ptr1];\n                ptr1++;\n                ptr3++;\n            }\n            else\n            {\n                arr[ptr3]=merge2[ptr2];\n                ptr2++;\n                ptr3++;\n            }\n        }\n        return arr;\n    }\n    vector<int> sortArray(vector<int>&nums) \n    {\n        return mergesorted(nums);\n    }\n};\n```
['C++']