sinat_14884161 于 2016.04.19 20:19 提问

#include
#include
int MaxValue(std::vectorb);

void BarrelSort(int c[], std::vectorb)
{
int max = MaxValue(b);
int* a=new int [max+1];
for (int i = 0; i < max+1; i++)
{
a[i] = 0;
}

``````for (std::vector<int>::iterator i = b.begin(); i !=b.end(); i++)
{
++a[*i];
}

//for (int i = 0; i < max+1; i++)
//{
//  std::cout << a[i] << std::endl;
//}

int k = 0;
for ( int i = 0; i < b.size(); )
{
if (a[k] > 0)
{
for (unsigned int j = 0; j < a[k]; j++, i++)
{
c[i] = k;

}
}
k++;

}

//delete[]a;为什么会报错
``````

}

int MaxValue(std::vectorb)
{
int max = b[0];
for (std::vector::iterator i = b.begin(); i < b.end(); i++)
{
max > *i ? max:max = *i;
}
return max;
}

int main()
{
int *t = new int[];
std::vectorc = { 9,2,3,7,6,4,8,9,2,3,4, };

``````BarrelSort(t, c);
for (unsigned int i = 0; i <c.size() ; i++)
{
std::cout << t[i] << std:: endl;
}
//delete[]t;为什么会报错
int s;
std::cin >> s;
``````

}

2个回答

qq423399099      2016.04.19 20:45

CSDNXIAON   2016.04.19 21:14

----------------------同志你好，我是CSDN问答机器人小N，奉组织之命为你提供参考答案，编程尚未成功，同志仍需努力！