Commit af6014b3 authored by ShahRukh's avatar ShahRukh

update merge-sort to reflect API update

parent 9e7f74fa
...@@ -27,18 +27,18 @@ vector<int> merge(vector<int> first,vector<int> second){ ...@@ -27,18 +27,18 @@ vector<int> merge(vector<int> first,vector<int> second){
if (left == 1){ if (left == 1){
v.push_back(first[countFirst]); v.push_back(first[countFirst]);
if ( first.size()> countFirst){ if ( first.size()> countFirst){
countFirst+=1; countFirst+=1;
} }
} }
else{ else{
v.push_back(second[countSecond]); v.push_back(second[countSecond]);
if (second.size()> countSecond){ if (second.size()> countSecond){
countSecond+=1; countSecond+=1;
} }
} }
} }
...@@ -57,8 +57,29 @@ vector<int> mergeSorting(vector<int> v){ ...@@ -57,8 +57,29 @@ vector<int> mergeSorting(vector<int> v){
} }
vector<int> sort_custom(vector<int> v){ vector<int> sort_custom(vector<int> v , int startidx, int endidx){
vector<int> sortVec = mergeSorting(v);
return sortVec; int size = v.size();
if (size < endidx || startidx > endidx) {
cout << "Invalid Input ";
vector<int> v;
return v;
}
else {
vector<int> initVector(v.cbegin(), v.cbegin()+startidx);
vector<int> subVector(v.cbegin()+startidx, v.cbegin()+endidx+1);
vector<int> endVector(v.cbegin()+endidx+1, v.cend());
vector<int> sortVec = mergeSorting(subVector);
initVector.insert( initVector.end(), sortVec.begin(), sortVec.end() );
initVector.insert( initVector.end(), endVector.begin(), endVector.end() );
return initVector;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment