#include<bits/stdc++.h>
using namespace std;
int main()
{
unordered_map<int, int> map;
int n;
int *arr = new int [n];
cin >> n;
for(int i=0; i<n; i++)
cin >> arr[i];
int max = arr[0];
for(int i=0; i<n; i++)
if(arr[i] > max)
max = arr[i];
for(int i=0; i<n; i++)
map[arr[i]] = 1;
int j = 0;
for(int i=0; i<=max; i++)
if(map[i] == 1)
arr[j++] = i;
for(int i=0; i<n; i++)
cout << arr[i] << " ";
}
Use a hash map and increase the value at the key (that is the value of arr[i]) by one. After that loop through the hash map till the max value of the array that you has been found at the beginning. Overwrite the array at index j whenever the value at the particular key is found greater than 1. The resultant array is sorted.
Note: This only only works on positive non-repeating integers.