算法题:将一个数组去重并从小到大排序
# include <iostream>
# include <vector>
# include <queue>
# include <algorithm>
using namespace std;
const int N = 100010;
int n, q[N];
void quick_sort(int q[], int l, int r)
{
if (l >= r) return ;
int i = l - 1, j = r + 1;
int mid = q[(l + r) / 2];
while (i < j)
{
do i ++; while (q[i] < mid);
do j --; while (q[j] > mid);
if (i < j) swap(q[i], q[j]);
}
quick_sort(q, l, j);
quick_sort(q, j+1, r);
}
int main()
{
cin >> n;
for (int i = 0; i < n; i ++) cin >> q[i];
quick_sort(q, 0, n-1);
int k = 1;
for (int i = 1; i < n; i ++)
{
if (q[i] != q[k-1]) q[k ++] = q[i];
}
for (int i = 0; i < k; i ++) cout << q[i] << ' ';
}