Witam wszystkich! Czy ktoś mógłby mi pomóc z moim kodem sortowania przez scalanie?
#include <iostream>
#include <vector>
using namespace std;
template<class typ>
void merge_f(vector<typ>&wektor,int p,int q,int r)
{
int n1=q-p+1;
int n2=r-q;
vector<typ>Left;
vector<typ>Right;
for(int i=0;i<n1;i++)
{
Left.push_back(wektor[p+i]);
}
for(int i=0;i<n2;i++)
{
Right.push_back(wektor[q+1+i]);
}
int i=0,j=0,sr=0;
while(i+p<=q && j+q+1<=r)
{
if(Left[i]<=Right[j])
wektor[(sr++)+p]=Right[j++];
else
wektor[(sr++)+p]=Left[i++];
}
if(i+p<q)
{
while(i+p<=q)
wektor[(sr++)+p]=Left[i++];
}
else if(j+q+1<r)
{
while(j+q+1<=r)
wektor[(sr++)+p]=Right[j++];
}
}
template<class typ>
void merge_sort(vector<typ>&wektor,int p,int r)
{
int q;
if(p<r)
{
q=(r-p)/2;
merge_sort(wektor,p,q);
merge_sort(wektor,q+1,r);
merge_f(wektor,p,q,r);
}
}
int main()
{
vector<int>numbers;
for(int i=10;i>0;i--)
numbers.push_back(i);
for(int i=0;i<10;i++)
cout<<numbers[i]<<endl;
merge_sort(numbers,0,9);
for(int i=0;i<10;i++)
cout<<numbers[i]<<endl;
}
po uruchomieniu wyrzuca błąd i po zamknieciu komunikatu w konsoli mam
Process returned 255 (0xFF)
z góry dzięki za odpowiedź ;)