Jeśli potrzebujesz to tylko posortować to prosta sprawa:
int arrayCounter[3] = {};
int sizeOfArray = 9;
//Your array with 1,2,3
int arrayWithNumbers[sizeOfArray] = { 2,2,3,1,1,1,2,1,3 };
for( int index = 0; index < sizeOfArray; ++index)
{
switch( arrayWithNumbers[index] )
{
case 1:
arrayCounter[0]++;
break;
case 2:
arrayCounter[1]++;
break;
case 3:
arrayCounter[2]++;
break;
}
}
int index = 0;
for( int iter = 1; iter <= 3; ++iter )
{
for( int attempt = 0; attempt <= arrayCounter[iter]; ++attempt )
{
arrayWithNumbers[index] = iter;
index++;
}
}
for( int index = 0; index < sizeOfArray; ++index )
{
std::cout << arrayWithNumbers[index] << " ";
}
OUTPUT:
1 1 1 1 2 2 2 3 3
http://cpp.sh/7nauc